예제 #1
0
        public ActionResult DoConfirm(OrderConfirmationModel model)
        {
            var usersRep = Locator.GetService<IUsersRepository>();

            // Ищем менеджера под заказ
            var manager =
                usersRep.Search(u => u.RoleId == 4)
                    .OrderBy(u => u.ManagedOrders.Count(o => o.Status >= 1 && o.Status <= 4))
                    .FirstOrDefault();

            if (manager == null)
            {
                ShowError("В системе не зарегистрировано менеджеров");
                return RedirectToAction("Confirm");
            }

            // Валидируем
            var order = CurrentUser.GetOrCreateCurrentOrder();
            if (order.GetTotalCount() <= 0)
            {
                ShowError("Заказ не может быть пустым");
                return RedirectToAction("Current");
            }

            // Присваиваем клиента
            Client client;
            if (model.ClientId == -1)
            {
                client = new Client()
                {
                    Address = model.Address,
                    Company = CurrentUser.Company,
                    DateCreated = DateTime.Now,
                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    Phone = model.Phone,
                    SurName = model.SurName
                };
                CurrentUser.Company.Clients.Add(client);
                usersRep.SubmitChanges();
            }
            else
            {
                client = CurrentUser.Company.Clients.FirstOrDefault(c => c.Id == model.ClientId);
                if (client == null)
                {
                    ShowError("Такой клиент не найден");
                    return RedirectToAction("Confirm");
                }
            }

            // Устанавливаем заказ
            order.Description = model.Description;
            order.DeliveryAddress = model.DeliveryAddress;
            client.Orders.Add(order);
            order.Status = (short) OrderStatus.Unverified;
            order.DateCreated = DateTime.Now;
            order.Manager = manager;
            manager.ManagedOrders.Add(order);

            // Добавляем этап жизни в заказ
            order.OrderStatusChangements.Add(new OrderStatusChangement()
            {
                AuthorId = CurrentUser.Id,
                Order = order,
                Status = (short)OrderStatus.Unverified,
                Comments = string.Format("Менеджер {0} назначен на заказ", manager.GetFio()),
                DateCreated = DateTime.Now
            });

            usersRep.SubmitChanges();

            PushNavigationItem("Заказы", "/orders/current");
            PushNavigationItem("Заказ подтвержден", "#");

            return View(order);
        }
예제 #2
0
		private void attach_Clients(Client entity)
		{
			this.SendPropertyChanging();
			entity.Company = this;
		}
예제 #3
0
		private void detach_Clients(Client entity)
		{
			this.SendPropertyChanging();
			entity.Company = null;
		}
예제 #4
0
        public ActionResult Save(Client model)
        {
            if (model.Id <= 0)
            {
                model.DateCreated = DateTime.Now;
                CurrentUser.Company.Clients.Add(model);
                Locator.GetService<ICompaniesRepository>().SubmitChanges();

                ShowSuccess("Клиент успешно добавлен");

                return RedirectToAction("Index");
            }
            else
            {
                var client = CurrentUser.Company.Clients.FirstOrDefault(c => c.Id == model.Id);
                if (client == null)
                {
                    ShowError("Такой клиент не найден");
                    return RedirectToAction("Index");
                }

                client.FirstName = model.FirstName;
                client.SurName = model.SurName;
                client.LastName = model.LastName;
                client.Phone = model.Phone;
                client.Email = model.Email;
                client.Address = model.Address;
                client.DateModified = DateTime.Now;

                Locator.GetService<ICompaniesRepository>().SubmitChanges();

                ShowSuccess("Клиент успешно отредактирован");

                return RedirectToAction("Index");
            }
        }