Exemplo n.º 1
0
        private void PrepareWorkStationViewModel(WorkStationViewModel model, MSDS_WorkStation entity)
        {
            IList <SelectListItem> selList = new List <SelectListItem>();
            IList <MSDS_WorkShop>  shops   = _workshopService.GetAll(WorkContext.CurrentMembershipUser.Company.Id);

            if (entity == null)
            {
                foreach (var item in shops)
                {
                    selList.Add(new SelectListItem {
                        Text = item.WorkShop_Name, Value = item.Id.ToString(), Selected = false
                    });
                }
            }
            else
            {
                foreach (var item in shops)
                {
                    selList.Add(new SelectListItem {
                        Text = item.WorkShop_Name, Value = item.Id.ToString(), Selected = item.Id == entity.WorkShop.Id
                    });
                }
            }
            model.WorkShops = selList;
        }
Exemplo n.º 2
0
 public void Add(MSDS_WorkStation entity)
 {
     if (_context.MSDS_WorkStation.Any(x => x.WorkStation_Name == entity.WorkStation_Name))
     {
         throw new Exception(string.Format("工位名称:{0} 已经存在", entity.WorkStation_Name));
     }
     _context.MSDS_WorkStation.Add(entity);
 }
Exemplo n.º 3
0
 public ActionResult AssignWorkStation(WorkerViewModel model)
 {
     try
     {
         using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
         {
             var entity = _workerService.Single(model.Id);
             if (entity != null)
             {
                 if (model.WorkStations_Seleted_Value != null)
                 {
                     entity.WorkStations.Clear();
                     if (model.WorkStations_Seleted_Value.Length != 0)
                     {
                         foreach (var item in model.WorkStations_Seleted_Value)
                         {
                             Guid             station_id = Guid.Parse(item);
                             MSDS_WorkStation station    = _workStationService.Single(station_id);
                             if (station != null)
                             {
                                 entity.WorkStations.Add(station);
                             }
                         }
                     }
                     unitOfWork.Commit();
                 }
                 SuccessNotification("编辑成功");
                 return(RedirectToAction("AssignWorkStation", new { id = model.Id }));
             }
             else
             {
                 ErrorNotification(new Exception("未能找到该工人"));
                 return(View());
             }
         }
     }
     catch (Exception ex)
     {
         ErrorNotification(ex);
         return(View());
     }
 }
Exemplo n.º 4
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));
            }
        }
Exemplo n.º 5
0
 public void Delete(MSDS_WorkStation entity)
 {
     _context.MSDS_WorkStation.Remove(entity);
 }
Exemplo n.º 6
0
 public void Delete(MSDS_WorkStation entity)
 {
     _repository.Delete(entity);
 }
Exemplo n.º 7
0
 public void Add(MSDS_WorkStation entity)
 {
     _repository.Add(entity);
 }