private void detach_FEAOrderItems(FEAOrderItem entity)
		{
			this.SendPropertyChanging();
			entity.FEAOrder = null;
		}
Beispiel #2
0
        public ActionResult ChangeOrderItemPrice(long id, long itemId, long productId, decimal price)
        {
            var order = DataContext.FEAOrders.FirstOrDefault(o => o.Id == id);
            if (order == null)
            {
                return Json(new
                {
                    success = false,
                    msg = "Заявка не найдена"
                });
            }

            // Ищем позицию
            FEAOrderItem orderItem;
            if (productId == 0 && itemId == 0)
            {
                orderItem = new FEAOrderItem()
                {
                    DateCreated = DateTime.Now,
                    FEAOrder = order,
                    Price = price,
                    Quantity = 0,
                    ProductId = order.Project.ProductTypes.First().Id
                };
                order.FEAOrderItems.Add(orderItem);
            }
            else
            {
                orderItem = order.FEAOrderItems.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_FEAOrderItems(FEAOrderItem entity)
		{
			this.SendPropertyChanging();
			entity.FEAOrder = this;
		}