예제 #1
0
        public ActionResult Edit(PlantFormModel model)
        {
            if (!ModelState.IsValid)
            {
                var errors       = ModelState.Values.SelectMany(x => x.Errors);
                var errorMessage = errors.Aggregate("", (current, error) => current + (error.ErrorMessage + "\n"));
                AddMessageInfo(errorMessage, Enums.MessageInfoType.Error);

                return(InitialEdit(model));
            }
            var isAlreadyExistMainPlant = IsMainPlantAlreadyExist(model.Detail.NPPBKC_ID, model.Detail.IsMainPlant,
                                                                  model.Detail.Werks);

            if (isAlreadyExistMainPlant)
            {
                AddMessageInfo("Main Plant Already Set", Enums.MessageInfoType.Warning);
                return(InitialEdit(model));
            }

            if (model.Detail.NPPBKC_ID == model.Detail.NPPBKC_IMPORT_ID)
            {
                AddMessageInfo("NPPBKC domestic cannot be the same as NPPBKC Import", Enums.MessageInfoType.Warning);
                return(InitialEdit(model));
            }
            try
            {
                var receiveMaterial = model.Detail.ReceiveMaterials.Where(c => c.IsChecked).ToList();
                model.Detail.ReceiveMaterials = receiveMaterial;
                var t1001w = Mapper.Map <Plant>(model.Detail);
                if (t1001w.PLANT_RECEIVE_MATERIAL != null)
                {
                    var tempRecieveMaterial = t1001w.PLANT_RECEIVE_MATERIAL;
                    foreach (var rm in tempRecieveMaterial)
                    {
                        rm.ZAIDM_EX_GOODTYP = _goodTypeBll.GetById(rm.EXC_GOOD_TYP);
                    }
                    t1001w.PLANT_RECEIVE_MATERIAL = tempRecieveMaterial;
                }

                _plantBll.save(t1001w, CurrentUser.USER_ID);
                AddMessageInfo(Constans.SubmitMessage.Saved, Enums.MessageInfoType.Success);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                AddMessageInfo(ex.Message, Enums.MessageInfoType.Error);

                return(InitialEdit(model));
            }
        }
        public JsonResult GoodTypeDescription(string goodTypeId)
        {
            var goodType = _goodTypeBll.GetById(goodTypeId);

            return(Json(goodType.EXT_TYP_DESC));
        }