コード例 #1
0
ファイル: MSDS_WorkerRepository.cs プロジェクト: junlu3/CMS
 public void Add(MSDS_Worker entity)
 {
     if (_context.MSDS_Worker.Any(x => x.Worker_ID == entity.Worker_ID && x.Company.Id == entity.Company.Id))
     {
         throw new Exception("该员工已存在!");
     }
     _context.MSDS_Worker.Add(entity);
 }
コード例 #2
0
 public void Delete(MSDS_Worker entity)
 {
     _repository.Delete(entity);
 }
コード例 #3
0
 public void Add(MSDS_Worker entity)
 {
     _repository.Add(entity);
 }
コード例 #4
0
ファイル: MSDS_WorkerRepository.cs プロジェクト: junlu3/CMS
 public void Delete(MSDS_Worker entity)
 {
     _context.MSDS_Worker.Remove(entity);
 }
コード例 #5
0
ファイル: WorkerController.cs プロジェクト: junlu3/CMS
        public ActionResult CreateOrUpdate(WorkerViewModel model)
        {
            try
            {
                if (string.IsNullOrEmpty(model.Worker_ID))
                {
                    ModelState.AddModelError("Worker_ID", "身份证号码不能为空");
                }
                if (string.IsNullOrEmpty(model.Worker_Name))
                {
                    ModelState.AddModelError("Worker_Name", "工人名字不能为空");
                }
                if (ModelState.IsValid)
                {
                    if (model.Id.ToString() == "00000000-0000-0000-0000-000000000000")
                    {
                        using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                        {
                            IList <MSDS_WorkStation> workStations = new List <MSDS_WorkStation>();

                            Company company = _companyService.GetById(WorkContext.CurrentMembershipUser.Company.Id);
                            var     entity  = new MSDS_Worker()
                            {
                                Id           = Guid.NewGuid(),
                                Worker_ID    = model.Worker_ID?.Trim(),
                                Worker_Name  = model.Worker_Name?.Trim(),
                                Company      = company,
                                WorkStations = workStations
                            };

                            _workerService.Add(entity);

                            unitOfWork.Commit();

                            SuccessNotification("添加成功");
                            //PrepareWorkerViewModel(model, entity);
                            return(View(model));
                        }
                    }
                    else
                    {
                        var entity = _workerService.Single(model.Id);
                        if (entity != null)
                        {
                            using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                            {
                                if (entity.Worker_ID != model.Worker_ID)
                                {
                                    if (_workerService.GetAll(WorkContext.CurrentMembershipUser.Company.Id).Any(x => x.Worker_ID == model.Worker_ID))
                                    {
                                        ErrorNotification(new Exception("身份证已存在"));
                                        //PrepareWorkerViewModel(model, entity);
                                        return(View(model));
                                    }
                                    else
                                    {
                                        entity.Worker_ID = model.Worker_ID?.Trim();
                                    }
                                }

                                entity.Worker_Name = model.Worker_Name?.Trim();



                                unitOfWork.Commit();
                                SuccessNotification("编辑成功");
                                //PrepareWorkerViewModel(model, entity);
                                return(View(model));
                            }
                        }
                        else
                        {
                            ErrorNotification(new Exception("编辑失败,未找到对应的车间"));
                            return(RedirectToAction("Index"));
                        }
                    }
                }
                else
                {
                    ErrorNotification(new Exception("编辑失败,输入信息有误"));
                    //PrepareWorkerViewModel(model, null);
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                ErrorNotification(ex);
                //PrepareWorkerViewModel(model, null);
                return(View(model));
            }
        }