예제 #1
0
        public async Task <string> Create(OrderWithoutUserCreateModel data, string userId)
        {
            modification = LogConstants.OrderCreated;

            if (data.Products.Count < 1)
            {
                throw new ArgumentException(ErrorMessages.InvalidProducts);
            }

            if (!this.db.DeliveryData.Any(d => d.Id == data.DeliveryDataId))
            {
                throw new ArgumentException(ErrorMessages.InvalidOrderId);
            }

            if (data.PromoCode != null)
            {
                await this.UpdatePromotionUsedQuota(data.PromoCode, data.PromotionsCount);
            }

            int number = await this.numerator.GetNextNumer(typeof(Order));

            Order order = new Order
            {
                Number = number,
                LastModificationDate = DateTime.Now,
                UserId         = userId,
                DeliveryDataId = data.DeliveryDataId,
                InvoiceDataId  = data.InvoiceDataId,
                Status         = OrderStatus.Ordered
            };

            await this.db.Orders.AddAsync(order);

            await this.db.SaveChangesAsync();

            string orderId = order.Id;

            await this.CreateProductOrders(order.Id, data.Products);

            await this.logger.Log(order.Id, userId, modification);

            return(orderId);
        }
예제 #2
0
        public async Task <IActionResult> CreateOrder([FromBody] OrderWithoutUserCreateModel order)
        {
            return(await this.Execute(false, true, async() =>
            {
                string orderId = await this.orders.Create(order, this.UserId);

                OrderDetailsModel orderModel = await this.orders.Get(orderId);

                string subject = string.Format(MailConstants.SubjectCreate, orderModel.Number);

                string receiverMail = MailConstants.OfficeMail;

                #if DEBUG
                receiverMail = MailConstants.DebugMail;
                #endif

                this.mails.Send(receiverMail, subject, "", smtpConfiguration);

                return this.Ok(new { orderId = orderId });
            }));
        }