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); }
public void Delete(MSDS_Worker entity) { _repository.Delete(entity); }
public void Add(MSDS_Worker entity) { _repository.Add(entity); }
public void Delete(MSDS_Worker entity) { _context.MSDS_Worker.Remove(entity); }
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)); } }