IWcsTaskTestApp.cs 2.13 KB
using System;
using System.Collections.Generic;
using System.Linq;
using Infrastructure;
using WebRepository;

namespace WebApp
{
    /// <summary>
    /// 模拟创建WCS任务测试接口App
    /// </summary>

    public partial class IWcsTaskTestApp : ApiApp
    {

        public IWcsTaskTestApp(IUnitWork unitWork, IAuth auth, BaseDBContext context) : base(unitWork, auth, context)
        {

        }

        public WCSResponse<WcsTask> CreateWcsTaskApp(TaskDetail td)
        {
            using (var tran = _context.Database.BeginTransaction())
            {
                WCSResponse<WcsTask> Response = new WCSResponse<WcsTask>();
                try
                {
                    if (td == null)
                    {
                        Response.Code = 500;
                        Response.Status = false;
                        Response.Message = "未传入任何有效数据!";
                    }
                    else
                    {
                        WcsTask wcsTask = new WcsTask();
                        wcsTask.TNo = td.TaskNo;
                        wcsTask.TNoWMS = td.TaskNo;
                        wcsTask.Type = td.TaskType;
                        wcsTask.PalletOrBoxNo = td.ContainerCode;
                        wcsTask.Priority = td.Priority;
                        wcsTask.Roadway = td.Roadway;
                        wcsTask.FromPlace = td.SourceLocation;
                        wcsTask.ToPlace = td.DestinationLocation;
                        wcsTask.EntrancePlace = td.Station;
                        wcsTask.ForkNo = int.Parse(td.MaterialName);
                        wcsTask.ExitPlace = td.Station;
                        _unitWork.Add(wcsTask);

                        tran.Commit();

                        Response.Result = wcsTask;
                    }
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    Response.Code = 500;
                    Response.Status = false;
                    Response.Message = ex.Message;
                }

                return Response;
            }
        }
    }
}