public virtual JsonResult AddOrder(AddOrderModel model, List <HttpPostedFileBase> attachments)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new ActionResponse <string> {
                    Message = LocalMessage.ValidationFailed
                }));
            }
            var addUser = _userSrv.Insert(model);

            if (!addUser.IsSuccessful)
            {
                return(Json(addUser));
            }

            model.UserId = addUser.Result;
            var userInRole = new UserInRole
            {
                UserId       = addUser.Result,
                RoleId       = int.Parse(AppSettings.EndUserRoleId),
                IsActive     = true,
                ExpireDateSh = PersianDateTime.Now.AddYears(5).ToString(PersianDateTimeFormat.Date)
            };

            if (!_userInRoleBusiness.Value.CheckExist(userInRole))
            {
                _userInRoleBusiness.Value.Insert(userInRole);
            }

            model.Status       = OrderStatus.WaitForPricing;
            model.DayToDeliver = byte.Parse(AppSettings.DefaultDayToDeliver);
            var addOrder = _orderSrv.Add(model);

            if (!addOrder.IsSuccessful)
            {
                return(Json(addUser));
            }

            var addFiles = _attachmentSrv.Insert(addOrder.Result, AttachmentType.OrderFiles, attachments);

            addOrder.Result.User = new User
            {
                FirstName    = model.FirstName,
                LastName     = model.LastName,
                Email        = model.Email,
                MobileNumber = long.Parse(model.MobileNumber)
            };

            return(Json(new
            {
                addFiles.IsSuccessful,
                addFiles.Message,
                Result = MvcExtention.RenderViewToString(this, MVC.Home.Views.Partials._AfterAdd, addOrder.Result)
            }));
        }
Beispiel #2
0
        public virtual JsonResult AddOrderAttachments(int orderId, AttachmentType attachmentType)
        {
            var files = new List <HttpPostedFileBase>();

            foreach (string fileName in Request.Files)
            {
                files.Add(Request.Files[fileName]);
            }
            var order = _orderBusiness.Value.Find(orderId);

            if (order == null)
            {
                return(Json(new { IsSuccessful = false, Message = LocalMessage.RecordsNotFound }));
            }
            return(Json(_attachmentBusiness.Insert(order, attachmentType, files)));
        }