Esempio n. 1
0
        // 新建寄件单
        public async Task <FunctionResult> CreateOrderSendingAsync(OrderSendingViewModel model, string userId)
        {
            try {
                context.Orders.Add(new Order()
                {
                    OrderType        = model.OrderType,
                    ExpressCompanyId = model.ExpressCompany,
                    Name             = model.Name,
                    Phone            = model.Phone,
                    Address          = model.Address,
                    ToAddress        = model.ToAddress,
                    ToName           = model.ToName,
                    Time             = model.Time,
                    Remark           = model.Remark,
                    UserId           = userId
                });
                await context.SaveChangesAsync();

                await ConfigManager.AddOrderCount(false);

                return(new FunctionResult());
            }
            catch (Exception e) {
                return(new FunctionResult(e));
            }
        }
Esempio n. 2
0
 public JsonResult IsOrderSendingValid(OrderSendingViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(Json(new JsonErrorObj(ModelState)));
     }
     return(Json(new JsonSucceedObj()));
 }
Esempio n. 3
0
        public async Task <JsonResult> OrderSending(OrderSendingViewModel model)
        {
            if (!ConfigManager.IsOrderSendingOnService)
            {
                return(Json(new JsonErrorObj("寄件服务暂时不开放")));
            }
            if (!ModelState.IsValid)
            {
                return(Json(new JsonErrorObj(ModelState)));
            }
            if (Request.IsAuthenticated)
            {
                FunctionResult result = await OrderManager.CreateOrderSendingAsync(model, User.Identity.GetUserId());

                if (result.IsSucceed)
                {
                    return(Json(new JsonSucceedObj()));
                }
                return(Json(new JsonErrorObj(result.ErrorMessage)));
            }
            ApplicationUser voidUser = await UserManager.CreateVoidUserAsync();

            if (voidUser != null)
            {
                UserManager.AddToRole(voidUser.Id, "Guest");
                SignInManager.SignIn(voidUser, true, true);
                FunctionResult result = await OrderManager.CreateOrderSendingAsync(model, voidUser.Id);

                if (result.IsSucceed)
                {
                    return(Json(new JsonSucceedObj()));
                }
                return(Json(new JsonErrorObj(result.ErrorMessage)));
            }
            else
            {
                return(Json(new JsonErrorObj("匿名用户申请失败")));
            }
        }