Exemplo n.º 1
0
        private void PopulateModel(m_Routing model, IDictionary values)
        {
            string ITEM_CODE     = nameof(m_Routing.ItemCode);
            string OPERATION_NO  = nameof(m_Routing.OperationNo);
            string PROCESS_CODE  = nameof(m_Routing.ProcessCode);
            string MACHINE_CODE  = nameof(m_Routing.MachineCode);
            string PIECE_PER_MIN = nameof(m_Routing.PiecePerMin);

            string TRANS_DATE  = nameof(m_Routing.TransDate);
            string CREATE_DATE = nameof(m_Routing.CreateDate);
            string MODIFY_BY   = nameof(m_Routing.ModifyBy);

            if (values.Contains(ITEM_CODE))
            {
                model.ItemCode = Convert.ToString(values[ITEM_CODE]);
            }

            if (values.Contains(OPERATION_NO))
            {
                model.OperationNo = Convert.ToInt32(values[OPERATION_NO]);
            }

            if (values.Contains(PROCESS_CODE))
            {
                model.ProcessCode = Convert.ToString(values[PROCESS_CODE]);
            }

            if (values.Contains(MACHINE_CODE))
            {
                model.MachineCode = Convert.ToString(values[MACHINE_CODE]);
            }

            if (values.Contains(PIECE_PER_MIN))
            {
                model.PiecePerMin = Convert.ToDecimal(values[PIECE_PER_MIN]);
            }

            if (values.Contains(TRANS_DATE))
            {
                model.TransDate = Convert.ToDateTime(values[TRANS_DATE]);
            }

            if (values.Contains(CREATE_DATE))
            {
                model.CreateDate = Convert.ToDateTime(values[CREATE_DATE]);
            }

            if (values.Contains(MODIFY_BY))
            {
                model.ModifyBy = Convert.ToString(values[MODIFY_BY]);
            }
        }
Exemplo n.º 2
0
        public IActionResult Post(string values)
        {
            var model   = new m_Routing();
            var _values = JsonConvert.DeserializeObject <IDictionary>(values);

            PopulateModel(model, _values);

            if (model.OperationNo <= 0)
            {
                return(BadRequest("OperationNo is negative please check data."));
            }

            if (model.ProcessCode == "")
            {
                return(BadRequest("ProcessCode is empty please check data."));
            }

            if (model.MachineCode == "")
            {
                return(BadRequest("MachineCode is empty please check data."));
            }

            if (model.PiecePerMin <= 0)
            {
                return(BadRequest("PiecePerMin is not equal to 0 please check data."));
            }

            var ResourceCheck = _context.m_Routing.Where(b => b.ItemCode == model.ItemCode && b.OperationNo == model.OperationNo).Count();

            if (ResourceCheck > 0)
            {
                return(BadRequest("Part No and OperationNo duplicate please check data."));
            }

            var ProcessCheck = _context.m_Routing.Where(b => b.ItemCode == model.ItemCode && b.ProcessCode == model.ProcessCode).Count();

            if (ProcessCheck > 0)
            {
                return(BadRequest("Part No and ProcessCode duplicate please check data."));
            }

            var OperationCheck = _context.m_Routing.Where(b => b.ItemCode == model.ItemCode).Count();

            if (OperationCheck > 25)
            {
                return(BadRequest("Operation greater than 25 please check data."));
            }

            if (model.ProcessCode == "Friction")
            {
                var Resource = _context.m_BOM.Where(b => b.ItemCode == model.ItemCode && b.Material1 == "" && b.Material2 == "").Count();
                if (Resource > 0)
                {
                    return(BadRequest("Process Friction Material1 and Material2 is empty please check data."));
                }
            }


            if (!TryValidateModel(model))
            {
                return(BadRequest(GetFullErrorMessage(ModelState)));
            }

            var identity = (ClaimsIdentity)User.Identity;
            IEnumerable <Claim> claims = identity.Claims;
            var c = claims.FirstOrDefault();

            model.TransDate  = DateTime.Now;
            model.CreateDate = DateTime.Now;
            model.ModifyBy   = c.Value;

            var result = _context.m_Routing.Add(model);

            _context.SaveChanges();

            return(Json(result.Entity.ItemCode));
        }