Example #1
0
 public void Add(MSDS_WorkShop entity)
 {
     if (_context.MSDS_WorkShop.Any(x => x.WorkShop_Name == entity.WorkShop_Name))
     {
         throw new Exception("车间名称已经存在");
     }
     _context.MSDS_WorkShop.Add(entity);
 }
Example #2
0
 public void Delete(MSDS_WorkShop entity)
 {
     _context.MSDS_WorkShop.Remove(entity);
 }
Example #3
0
 public void Delete(MSDS_WorkShop entity)
 {
     _repository.Delete(entity);
 }
Example #4
0
 public void Add(MSDS_WorkShop entity)
 {
     _repository.Add(entity);
 }
Example #5
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));
            }
        }
Example #6
0
 private void PrepareWorkShopViewModel(WorkShopViewModel model, MSDS_WorkShop entity)
 {
 }