Пример #1
0
        private OrdersFormViewModel GetOrderFormViewModel(int?orderID, OrdersFormViewModel model = null)
        {
            var order = UnitOfWork.OrderRepository.GetWithStatus(orderID);

            if (order == null || (UserItem.Role.Code == RoleCode.BROCKER && order.Status.IntCode != OrderStatus.PENDING))
            {
                return(null);
            }
            else
            {
                if (model == null)
                {
                    model = new OrdersFormViewModel
                    {
                        Firstname    = order.Firstname,
                        Lastname     = order.Lastname,
                        Address      = order.Address,
                        Mobile       = order.Mobile,
                        DeliveryTime = order.DeliveryTime?.ToString(Resources.FormatDate),
                        Note         = order.Note,
                        Status       = order.Status?.Caption,
                        StatusColor  = order.Status?.StringCode
                    };
                }
                model.UserID   = order.UserID;
                model.StatusID = order.StatusID;
                model.ClientID = order.ClientID;
                model.SaveOrderPropertiesUrl = Url.RouteUrl("OrdersEdit", new { ID = orderID });
                model.OrdersUrl = Url.RouteUrl("Orders");
                model.OrderDetailsGridViewModel = GetOrderDetailsGridViewModel(orderID);
            }

            return(model);
        }
Пример #2
0
        public ActionResult OrdersEdit(OrdersFormViewModel model)
        {
            var ajaxResponse = new AjaxResponse();
            var errors       = Validation.ValidateOrderEditForm(model.Firstname, model.Lastname, model.Address, model.Mobile, model.DeliveryTime);

            if (errors.Count == 0)
            {
                model = GetOrderFormViewModel(model.ID, model);

                if (model == null)
                {
                    ajaxResponse.Data = new
                    {
                        RedirectUrl = Url.RouteUrl("NotFound")
                    };
                }
                else
                {
                    UnitOfWork.OrderRepository.Update(new Order
                    {
                        ID           = model.ID,
                        UserID       = model.UserID,
                        StatusID     = model.StatusID,
                        ClientID     = model.ClientID,
                        Firstname    = model.Firstname,
                        Lastname     = model.Lastname,
                        Address      = model.Address,
                        Mobile       = model.Mobile,
                        DeliveryTime = model.DeliveryTime.ToDateTime(),
                        Note         = model.Note
                    });

                    UnitOfWork.Complate();

                    if (UnitOfWork.IsError)
                    {
                        ajaxResponse.Data = new
                        {
                            Message = Resources.Abort
                        };
                    }
                    else
                    {
                        ajaxResponse.IsSuccess = true;
                        ajaxResponse.Data      = new
                        {
                            Message = Resources.Success
                        };
                    }
                }
            }
            else
            {
                ajaxResponse.Data = new
                {
                    ErrorsJson = errors.ToJson()
                };
            }

            return(Json(ajaxResponse));
        }