Esempio n. 1
0
        public void CreateFromAdmin(Order order)
        {
            if (order == null)
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));

            orderRepository.InsertOrUpdate(order);
            orderRepository.Save();
        }
Esempio n. 2
0
        public void Create(Order order)
        {
            if(order == null)
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest));

            orderRepository.InsertOrUpdateWithPerson(order, User.Identity.Name);
            orderRepository.Save();
        }
Esempio n. 3
0
        public virtual MailMessage OrderSent(string userEmail, Order order)
        {
            var mailMessage = new MailMessage { Subject = "Заказ отправлен" };
            ViewBag.order = order;
            mailMessage.To.Add(userEmail);
            PopulateBody(mailMessage, viewName: "OrderSent");

            return mailMessage;
        }
Esempio n. 4
0
        public void DeletedDetails(Order order, IEnumerable<int> deleted_detail_list)
        {
            for (int i = 0; i < deleted_detail_list.Count() - 1; i++)
            {
                OrderDetail detail = context.OrderDetails.Find(deleted_detail_list.ElementAt(i));
                if (detail != null)
                    context.OrderDetails.Remove(detail);
            }
            //CreditOperation cp = context.CreditOperations.SingleOrDefault(o => o.Order.Id == order.Id);
            //if (cp != null)
            //    cp.Amount = order.OrderDetail.Sum(od => od.Product.Price * od.Quantity);
            //order.Person.CalculateBalance();

            if (order.OrderDetail.Count == 0)
            {
                order.Statuses.Clear();
                context.Orders.Remove(order);
            }
        }
Esempio n. 5
0
        private dynamic Order_(Order order)
        {
            dynamic dynamic_order = new JsonObject();
            dynamic_order.Id = order.Id;
            dynamic_order.Date = order.Date;
            dynamic_order.CurrentStatus = order.Statuses.SingleOrDefault(s => s.isCurrent).StatusValue;

            dynamic_order.Person = Person_(order.Person);

            dynamic details = new JsonArray();
            foreach (OrderDetail detail in order.OrderDetail)
            {
                dynamic json_detail = new JsonObject();
                json_detail.Id = detail.Id;
                json_detail.Quantity = detail.Quantity;
                dynamic product = new JsonObject();
                product.Id = detail.Product.Id;
                product.Price = detail.Product.Price;
                product.Summary = detail.Product.Summary;
                product.Title = detail.Product.Title;
                product.isComplex = detail.Product.isComplex;
                json_detail.Product = product;

                details.Add(json_detail);
            }
            dynamic_order.OrderDetail = details;
            return dynamic_order;
        }
Esempio n. 6
0
 private string GetOrderJsonValue(Order order)
 {
     return Order_(order).ToString();
 }
Esempio n. 7
0
        public void InsertOrUpdate(Order order)
        {
            if (order.Id == default(int)) {
                // New entity
                foreach (var detail in order.OrderDetail)
                {
                    detail.Product = context.Products.Find(detail.Product.Id);
                }

                order.Statuses.Add(new OrderStatus { Date = DateTime.Now, isCurrent = true, StatusValue = (int)OrderStatusValue.Order });

                context.Orders.Add(order);
            } else {
                foreach (var detail in order.OrderDetail)
                {
                    detail.Product = context.Products.Find(detail.Product.Id);
                    context.Entry(detail).State = EntityState.Modified;
                    if (detail.Id == default(int))
                    {
                        context.OrderDetails.Add(detail);
                    }
                }
                context.Entry(order).State = EntityState.Modified;
            }
        }
Esempio n. 8
0
        public void InsertOrUpdateWithPerson(Order order, string domainName)
        {
            if (order.Id == default(int))
            {
                Person person = context.People.SingleOrDefault(p => p.DomainName == domainName);
                order.Person = person;

                foreach (var detail in order.OrderDetail)
                {
                    detail.Product = context.Products.Find(detail.Product.Id);
                }

                order.Statuses.Add(new OrderStatus { Date = DateTime.Now, isCurrent = true, StatusValue = (int)OrderStatusValue.Order });

                //decimal amount = order.OrderDetail.Sum(od => od.Product.Price * od.Quantity);
                //person.Operations.Add(new CreditOperation { Date = DateTime.Now, Order = order, Amount = amount, Summary = "Заказ" });
                //person.CalculateBalance();
                context.Orders.Add(order);
            }
            else
            {
                //Person person = context.People.SingleOrDefault(p => p.DomainName == domainName);
                //order.Person = person;

                foreach (var detail in order.OrderDetail)
                {
                    detail.Product = context.Products.Find(detail.Product.Id);
                    context.Entry(detail).State = EntityState.Modified;
                    if (detail.Id == default(int))
                    {
                        context.OrderDetails.Add(detail);
                    }
                }
                //CreditOperation operation = context.CreditOperations.SingleOrDefault(o => o.Order.Id == order.Id);
                //operation.Amount = order.OrderDetail.Sum(od => od.Product.Price * od.Quantity);
                //order.Person.CalculateBalance();
                //context.Entry(operation).State = EntityState.Modified;

                context.Entry(order).State = EntityState.Modified;
            }
        }