Пример #1
0
        private void InitModelSubOrders(CompanyOrderCreateViewModel model)
        {
            var companyId           = WorkContext.CurrentMembershipUser.Company.Id;
            var searchSubOrderModel = new CompanySubOrderSearchModel
            {
                CompanyId          = companyId,
                SelectedBookStatus = 18,
                PageIndex          = 1,
                PageSize           = int.MaxValue
            };
            var subOrders = _companySubOrderService.Search(searchSubOrderModel);

            LoadSubOrders(model, subOrders);
        }
Пример #2
0
 private void LoadSubOrders(CompanyOrderCreateViewModel model, IPagedList <CompanySubOrder> subOrders)
 {
     foreach (var item in subOrders)
     {
         if (model.AssignedSubOrders.FirstOrDefault(x => x.Id == item.Id) == null)
         {
             model.NotAssignedSubOrders.Add(item);
         }
     }
     foreach (var item in model.AssignedSubOrders)
     {
         model.AssignedSubOrderString += item.Id.ToString() + ",";
     }
     if (model.AssignedSubOrders.Count > 0)
     {
         model.AssignedSubOrderString = model.AssignedSubOrderString.Substring(0, model.AssignedSubOrderString.Length - 1);
     }
 }
Пример #3
0
        public ActionResult View(Guid id)
        {
            var model = new CompanyOrderCreateViewModel();

            using (UnitOfWorkManager.NewUnitOfWork())
            {
                if (id != null)
                {
                    var order = _companyOrderService.GetById(new Guid(id.ToString()));
                    model.Comment           = order.Comment;
                    model.OrderId           = order.Id;
                    model.AssignedEmployees = order.CompanyEmployees;
                    model.AssignedSubOrders = order.SubOrders;
                }

                InitModelSubOrders(model);
                InitModelEmployees(model);
            }
            return(View(model));
        }
Пример #4
0
        private void InitModelEmployees(CompanyOrderCreateViewModel model)
        {
            var company            = WorkContext.CurrentMembershipUser.Company;
            var allCompanEmployees = company.CompanyEmployees;

            if (model.AssignedEmployees.Count > 0)
            {
                foreach (var item in allCompanEmployees)
                {
                    if (model.AssignedEmployees.FirstOrDefault(x => x.Id == item.Id) == null)
                    {
                        model.NotAssignedEmployees.Add(item);
                    }
                }
                foreach (var item in model.AssignedEmployees)
                {
                    model.AssignedEmployeesString += (item.Id.ToString() + ",");
                }

                model.AssignedEmployeesString = model.AssignedEmployeesString.Substring(0, model.AssignedEmployeesString.Length - 1);
            }
        }
Пример #5
0
        public ActionResult Create(CompanyOrderCreateViewModel model, FormCollection form)
        {
            try
            {
                var  company   = WorkContext.CurrentMembershipUser.Company;
                Guid companyId = company.Id;

                using (var unitOfWork = UnitOfWorkManager.NewUnitOfWork())
                {
                    var order = new CompanyOrder();

                    if (model.OrderId == null)
                    {
                        order.Comment = model.Comment;
                        if (!string.IsNullOrEmpty(model.AssignedSubOrderString))
                        {
                            var subOrderIds = model.AssignedSubOrderString.Split(',');
                            GenerateOrderSubOrders(order, subOrderIds);
                        }
                        if (!string.IsNullOrEmpty(model.AssignedEmployeesString))
                        {
                            var employeeIds = model.AssignedEmployeesString.Split(',');
                            GenerateEmployees(order, employeeIds);
                        }
                        order.Company          = _companyService.GetById(companyId);
                        order.IsBuildCompleted = false;
                        order.Locked           = false;
                        order.CreatedBy        = WorkContext.CurrentMembershipUser.Username;
                        order.CreatedDate      = DateTime.Now;
                        _companyOrderService.Add(order);
                    }
                    else
                    {
                        order         = _companyOrderService.GetById(new Guid(model.OrderId.ToString()));
                        order.Comment = model.Comment;
                        order.SubOrders.Clear();
                        if (!string.IsNullOrEmpty(model.AssignedSubOrderString))
                        {
                            var subOrderIds = model.AssignedSubOrderString.Split(',');
                            GenerateOrderSubOrders(order, subOrderIds);
                        }
                        order.CompanyEmployees.Clear();
                        if (!string.IsNullOrEmpty(model.AssignedEmployeesString))
                        {
                            var employeeIds = model.AssignedEmployeesString.Split(',');
                            GenerateEmployees(order, employeeIds);
                        }
                        order.Company          = _companyService.GetById(companyId);
                        order.IsBuildCompleted = false;
                        order.Locked           = model.IsLocked;
                        order.UpdatedBy        = WorkContext.CurrentMembershipUser.Username;
                        order.UpdatedDate      = DateTime.Now;
                    }
                    model.AssignedSubOrders = order.SubOrders;
                    model.AssignedEmployees = order.CompanyEmployees;
                    model.OrderId           = order.Id;
                    unitOfWork.Commit();

                    SuccessNotification("保存成功");
                }
            }
            catch (Exception e)
            {
                ErrorNotification(e);
            }
            using (UnitOfWorkManager.NewUnitOfWork())
            {
                InitModelSubOrders(model);
                InitModelEmployees(model);
            }
            return(View(model));
        }