public static bool CreateProduct(string productName) { var result = false; try { var entities = new AycemEntities(); var porduct = new Porduct { ProductId = Guid.NewGuid(), ProductName = productName }; entities.Porduct.Add(porduct); result = entities.SaveChanges() > 0; } catch (Exception ex) { throw; } return(result); }
public static bool CreateOrder(OrderDTO orderDTO) { var result = false; try { var entities = new AycemEntities(); var order = new Order { OrderId = Guid.NewGuid(), OrderQuantity = 0, OrderExpiryDate = orderDTO.OrderExpiryDate, // ModifierRoleId = orderDTO.ModifierRoleId, CompanyId = orderDTO.CompanyId }; entities.Order.Add(order); result = entities.SaveChanges() > 0; var newId = order.OrderId; if (orderDTO.Items != null) { foreach (var item in orderDTO.Items) { var orderItem = new OrderItem { OrderId = newId, ProductId = item.ProductId, Quantity = item.Quantity, ColourId = item.ColourId, OrderItemId = item.OrderItemId }; entities.OrderItem.Add(orderItem); } entities.SaveChanges(); } if (orderDTO.Products != null) { foreach (var product in orderDTO.Products) { var porduct = new Porduct { ProductId = product.ProductId, ProductName = product.ProductName, }; entities.Porduct.Add(porduct); entities.SaveChanges(); } //if (orderDTO.Companies != null) { // foreach (var companies in orderDTO.Companies) // { // var company = new Company // { // CompanyId = companies.CompanyId, // CompanyName = companies.CompanyName, // CompanyTelNo = companies.CompanyTelNo // }; // entities.Company.Add(company); // entities.SaveChanges(); // } // } } } catch (Exception ex) { throw; } return(result); }