public ProductServiceAddEditModel AddOrder(OrderServiceAddEditModel model) { ProductServiceAddEditModel rModel = new ProductServiceAddEditModel(); try { Order addOrder = new Order(); if (model.OrderId == 0) { _orderRepository.Add(addOrder); } else { addOrder = _orderRepository.GetById(model.OrderId); } var productData = _productRepository.GetById(model.OrderItemId); OrderItem addItem = new OrderItem() { ProductId = model.OrderItemId, OrderId = addOrder.Id, Qty = 1, Price = productData.Price }; _orderItemRepository.Add(addItem); rModel.Success = true; rModel.Update = false; rModel.OrderId = addOrder.Id; rModel.Id = addItem.ProductId; rModel.Price = productData.Price; rModel.Qty = 1; return(rModel); } catch (Exception error) { _errorLogService.AddError(new ErrorLogServiceModel { error = error, Location = "OrderService", Method = "AddOrder", OtherInfo = "" }); rModel.Success = false; rModel.Update = false; rModel.Id = 0; return(rModel); } }