Exemple #1
0
        public async Task <JsonResult> Booking(OrderEditViewModel request, [NamedModelBinder(typeof(CommaSeparatedModelBinder), "attachmentIds")] string[] attachmentIds)
        {
            if (!ModelState.IsValid)
            {
                return(Json(false, data: ErrorToDictionary()));
            }

            var order = Mapper.Map <OrderEditViewModel, Order>(request);
            var serialNumberManager = new SerialNumberManager(User);
            var manager             = new OrderManager(User);

            if (string.IsNullOrEmpty(order.Id))
            {
                order.Id = SaleManagentConstants.Misc.OrderPrefix + await serialNumberManager.NextSNAsync(SaleManagentConstants.SerialNames.Order);
            }
            else
            {
                order.Id = order.Id.Trim();

                if (order.Id.Length != 12)
                {
                    return(Json(false, "订单号格式不正确"));
                }

                if (await manager.GetOrderAsync(order.Id) != null)
                {
                    return(Json(false, "订单号已存在"));
                }
            }
            if (attachmentIds.Any())
            {
                order.Attachments = new List <OrderAttachment>();
                attachmentIds.ForEach <string>(a =>
                                               order.Attachments.Add(new OrderAttachment
                {
                    FileInfoId = a,
                    OrderId    = order.Id,
                    CreatorId  = User.Id
                }));
            }
            var result = await manager.CreateOrder(order);

            if (result.Succeeded)
            {
                var operationLogManager = new OrderOperationLogManager(User);
                await operationLogManager.AddLogAsync(OrderStatus.UnConfirmed, order.Id);

                return(Json(result.Succeeded, data:
                            new
                {
                    orderId = order.Id
                }));
            }

            return(Json(result));
        }
Exemple #2
0
        public async Task <JsonResult> Create(SpotGoodsEditViewModel request)
        {
            if (!ModelState.IsValid)
            {
                return(Json(false, data: ErrorToDictionary()));
            }

            var basicDataManager = new BasicDataManager();
            var matchStones      = await basicDataManager.GetMatchStonesAsync();

            JArray jarry = JArray.Parse(Request.Form["SetStoneInfos"]);
            List <SpotGoodsSetStoneInfo> SpotGoodsSetStoneInfos = new List <SpotGoodsSetStoneInfo>();

            var spotGoods = Mapper.Map <SpotGoodsEditViewModel, SpotGoods>(request);

            var serialNumberManager = new SerialNumberManager(User);
            var manager             = new SpotGoodsManager(User);

            if (string.IsNullOrEmpty(spotGoods.Id))
            {
                spotGoods.Id = SaleManagentConstants.Misc.SpotGoodsPrefix + await serialNumberManager.NextSNAsync(SaleManagentConstants.SerialNames.SpotGoods);
            }
            for (int i = 0; i < jarry.Count; ++i)  //遍历JArray
            {
                var setStoneInfo = Newtonsoft.Json.JsonConvert.DeserializeObject <SpotGoodsSetStoneInfo>(jarry[i].ToString());
                var matchStone   = matchStones.FirstOrDefault(r => r.Id == setStoneInfo.MatchStoneId);
                if (matchStone == null)
                {
                    break;
                }

                setStoneInfo.Price       = matchStone.Price;
                setStoneInfo.WorkingCost = (int)matchStone.WorkingCost * setStoneInfo.Number;
                setStoneInfo.CreatorId   = User.Id;
                setStoneInfo.SpotGoodsId = spotGoods.Id;
                SpotGoodsSetStoneInfos.Add(setStoneInfo);
            }
            spotGoods.SetStoneInfos = SpotGoodsSetStoneInfos;
            var result = await manager.CreateSpotGoods(spotGoods);

            return(Json(result));
        }
Exemple #3
0
        public async Task <JsonResult> Create(ShipmentOrderViewModel shipmentOrderViewModel)
        {
            var shipmentOrder = new ShipmentOrder();

            shipmentOrder = Mapper.Map <ShipmentOrderViewModel, ShipmentOrder>(shipmentOrderViewModel);

            var usermanager = new UserManager();
            var customer    = usermanager.FindByIdByCache(shipmentOrder.CustomerId);

            shipmentOrder.CustomerName = customer.Name;

            var serialNumberManager = new SerialNumberManager(User);

            shipmentOrder.Id = SaleManagentConstants.Misc.ShipmentOrderPrefix + await serialNumberManager.NextSNAsync(SaleManagentConstants.SerialNames.ShipmentOrder);

            shipmentOrder.CompanyId = User.CompanyId;
            shipmentOrder.ShipmentOrderInfos.Each(r => r.ShipmentOrderId = shipmentOrder.Id);
            var shipmentManager = new ShipmentManager(User);
            var result          = await shipmentManager.CreateAsync(shipmentOrder);

            if (result.Succeeded)
            {
                var orderIds = shipmentOrder.ShipmentOrderInfos.Select(r => r.Id);
                await new OrderManager(User).UpdateOrderStatusAsync(OrderStatus.Shipmenting, orderIds);
                await new OrderOperationLogManager(User).AddLogAsync(OrderStatus.Shipmenting, orderIds);
            }
            return(Json(result.Succeeded, "", result.Data));
        }