private void detach_LeadOrderItems(LeadOrderItem entity)
		{
			this.SendPropertyChanging();
			entity.LeadOrder = null;
		}
Esempio n. 2
0
        public ActionResult ChangeOrderItemPrice(long id, long itemId, long productId, decimal price)
        {
            var order = DataContext.LeadOrders.FirstOrDefault(o => o.Id == id);
            if (order == null)
            {
                return Json(new
                {
                    success = false,
                    msg = "Заказ не найден"
                });
            }

            if (order.Status != (short)LeadOrderStatus.Initial)
            {
                return Json(new
                {
                    success = false,
                    msg = "Нельзя редактировать позиции заказа в этом статусе"
                });
            }

            // Ищем позицию
            LeadOrderItem orderItem;
            if (productId == 0 && itemId == 0)
            {
                orderItem = new LeadOrderItem()
                {
                    LeadOrder = order,
                    Price = price,
                    Quantity = 0,
                    ProductId = order.Project.ProductTypes.First().Id
                };
                order.LeadOrderItems.Add(orderItem);
            }
            else
            {
                orderItem = order.LeadOrderItems.FirstOrDefault(oi => oi.Id == itemId);
                if (orderItem == null)
                {
                    return Json(new
                    {
                        success = false,
                        msg = "Такая позиция не найдена"
                    });
                }

                // Изменяем количество
                orderItem.Price = price;
            }

            // Пытаемся сохранить
            try
            {
                DataContext.SubmitChanges();
            }
            catch (Exception e)
            {
                return Json(new
                {
                    success = false,
                    msg = e.Message
                });
            }

            // Отдаем успешный результат
            return Json(new
            {
                success = true,
                id = orderItem.Id,
                productId = orderItem.ProductId
            });
        }
		private void attach_LeadOrderItems(LeadOrderItem entity)
		{
			this.SendPropertyChanging();
			entity.LeadOrder = this;
		}