예제 #1
0
 public ActionResult CreateOrUpdate(Guid?id = null)
 {
     try
     {
         if (id != null)
         {
             var entity = _workShopService.Single(id.Value);
             if (entity != null)
             {
                 var model = new WorkShopViewModel
                 {
                     Id            = entity.Id,
                     WorkShop_Name = entity.WorkShop_Name.Trim(),
                     Company_Id    = entity.Company.Id
                 };
                 PrepareWorkShopViewModel(model, entity);
                 return(View(model));
             }
             else
             {
                 ErrorNotification(new Exception("加载失败,未找到该车间"));
                 return(RedirectToAction("Index"));
             }
         }
         else
         {
             WorkShopViewModel model = new WorkShopViewModel();
             PrepareWorkShopViewModel(model, null);
             return(View(model));
         }
     }
     catch (Exception ex)
     {
         ErrorNotification(new Exception("车间编辑页面加载失败" + ex.Message));
         return(RedirectToAction("Index"));
     }
 }
예제 #2
0
        public ActionResult CreateOrUpdate(WorkStationViewModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.WorkStation_Name))
                {
                    ModelState.AddModelError("WorkStation_Name", "名称不能为空");
                }
                if (string.IsNullOrEmpty(model.WorkShop_Id))
                {
                    ModelState.AddModelError("WorkShop_Id", "车间不能为空");
                }
                if (ModelState.IsValid)
                {
                    if (model.Id.ToString() == "00000000-0000-0000-0000-000000000000")
                    {
                        using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                        {
                            Guid          workshop_Id = Guid.Parse(model.WorkShop_Id);
                            MSDS_WorkShop workShop    = _workshopService.Single(workshop_Id);
                            var           entity      = new MSDS_WorkStation()
                            {
                                Id = Guid.NewGuid(),
                                WorkStation_Name = model.WorkStation_Name.Trim(),
                                WorkShop         = workShop
                            };
                            _workstationService.Add(entity);

                            unitOfWork.Commit();

                            SuccessNotification("添加成功");
                            PrepareWorkStationViewModel(model, entity);
                            return(View(model));
                        }
                    }
                    else
                    {
                        var entity = _workstationService.Single(model.Id);
                        if (entity != null)
                        {
                            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                            {
                                if (entity.WorkStation_Name != model.WorkStation_Name)
                                {
                                    if (_workstationService.GetAll(WorkContext.CurrentMembershipUser.Company.Id).Any(x => x.WorkStation_Name == model.WorkStation_Name))
                                    {
                                        ErrorNotification(new Exception("工位名已存在"));
                                        PrepareWorkStationViewModel(model, entity);
                                        return(View(model));
                                    }
                                    else
                                    {
                                        entity.WorkStation_Name = model.WorkStation_Name.Trim();
                                        unitOfWork.Commit();
                                        SuccessNotification("编辑成功");
                                        PrepareWorkStationViewModel(model, entity);
                                        return(View(model));
                                    }
                                }
                                else
                                {
                                    SuccessNotification("编辑成功");
                                    PrepareWorkStationViewModel(model, entity);
                                    return(View(model));
                                }
                            }
                        }
                        else
                        {
                            ErrorNotification(new Exception("编辑失败,未找到对应的车间"));
                            return(RedirectToAction("Index"));
                        }
                    }
                }
                else
                {
                    ErrorNotification(new Exception("编辑失败,输入信息有误"));
                    PrepareWorkStationViewModel(model, null);
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                ErrorNotification(ex);
                PrepareWorkStationViewModel(model, null);
                return(View(model));
            }
        }