public string Add(ItemDTO item) { using (var _context = new OSContext()) { Item item1; if (item.ID == 0) { item1 = _context.Items.FirstOrDefault(i => i.Name == item.Name); if (item1 != null) { throw new WebFaultException <string>("Item Already Exists", HttpStatusCode.Conflict); } } Category category = _context.Categories.FirstOrDefault(c => c.ID == item.CategoryID); if (category == null) { throw new WebFaultException <string>("Category Not Found", HttpStatusCode.Conflict); } item1 = new Item() { ID = item.ID, Name = item.Name, CategoryID = item.CategoryID, Cost = item.Cost, Descripition = item.Descripition, ImageURL = item.ImageURL, NumberOfSold = 0, Category = category }; _context.Items.AddOrUpdate(item1); _context.SaveChanges(); return("Item Added Succefuly"); } }
public int SaveOrder(Order order) { using (var context = new OSContext()) { context.Orders.Add(order); return(context.SaveChanges()); } }
public void UpdateCategory(Category category) { using (var context = new OSContext()) { context.Entry(category).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void SaveCategory(Category category) { using (var context = new OSContext()) { context.Categories.Add(category); context.SaveChanges(); } }
public void UpdateProduct(Product product) { using (var context = new OSContext()) { context.Entry(product).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
public void DeleteProduct(int ID) { using (var context = new OSContext()) { var product = context.Products.Find(ID); context.Products.Remove(product); context.SaveChanges(); } }
public void DeleteProduct(int ID) { using (var context = new OSContext()) { //context.Entry(product).State = System.Data.Entity.EntityState.Deleted; var product = context.Products.Find(ID); context.Products.Remove(product); context.SaveChanges(); } }
public void SaveProduct(Product product) { using (var context = new OSContext()) { context.Entry(product).State = System.Data.Entity.EntityState.Unchanged; context.Products.Add(product); context.SaveChanges(); } }
public bool UpdateOrderStatus(int ID, string status) { using (var context = new OSContext()) { var order = context.Orders.Find(ID); order.Status = status; //context.Entry(order).State = EntityState.Modified; //If order status giving error then active this... return(context.SaveChanges() > 0); } }
public void DeleteCategory(int ID) { using (var context = new OSContext()) { var category = context.Categories.Where(x => x.ID == ID).Include(x => x.Products).FirstOrDefault(); context.Products.RemoveRange(category.Products); // first delete products of this category context.Categories.Remove(category); context.SaveChanges(); } }
public string PlaceOrder(OrderDTO order) { using (OSContext _context = new OSContext()) { Order newOrder = new Order() { ReciverFullName = order.FullName, Address = order.Address, ZIPCode = order.Zip, Country = order.Country, City = order.City, PaymentTypeID = order.paymentType.ID, UserID = order.user.ID }; User user = _context.Users.FirstOrDefault(u => u.ID == newOrder.UserID); if (user == null) { throw new WebFaultException <string>("User Dosent Exist", HttpStatusCode.NotFound); } PaymentType Payment = _context.PaymentTypes.FirstOrDefault(p => p.ID == newOrder.PaymentTypeID); if (Payment == null) { throw new WebFaultException <string>("Payment Dosent Exist", HttpStatusCode.NotFound); } for (int i = 0; i < order.products.Count; i++) { newOrder.TotalCost += _context.Items.FirstOrDefault(it => it.ID == order.products[i].Key).Cost *order.products[i].Value; } _context.Orders.Add(newOrder); for (int i = 0; i < order.products.Count; i++) { OrderItem orderitem = new OrderItem() { OrderID = newOrder.ID, ItemID = order.products[i].Key, Quantity = order.products[i].Value }; _context.OrderItems.Add(orderitem); } _context.SaveChanges(); return("Order Added Successfully"); } }
public bool UpdateOrderStatus(int ID, string status) { using (var context = new OSContext()) { var order = context.Orders.Find(ID); order.Status = status; context.Entry(order).State = EntityState.Modified; return(context.SaveChanges() > 0); } }
public string Delete(int itemID) { using (var _context = new OSContext()) { Item item = _context.Items.FirstOrDefault(i => i.ID == itemID); if (item == null) { throw new WebFaultException <string>("Item Not Exists", HttpStatusCode.Conflict); } _context.Items.Remove(item); _context.SaveChanges(); return("Item Deleted"); } }
public string Add(CategoryDTO category) { Category newcategory = new Category() { Name = category.Name }; if (_context.Categories.FirstOrDefault(c => c.Name == newcategory.Name) != null) { throw new WebFaultException <string>("Category Already Exists", HttpStatusCode.Conflict); } _context.Categories.Add(newcategory); _context.SaveChanges(); return("Category Added Successfully"); }
public UserDTO Register(UserDTO user) { User user1 = _context.Users.FirstOrDefault(u => u.Email == user.Email); if (user1 != null) { throw new WebFaultException <string>("Email Already Exists", HttpStatusCode.Conflict); } user1 = new User() { Email = user.Email, FirstName = user.FirstName, LastName = user.LastName, Password = user.Password, IsAdmin = false }; _context.Users.Add(user1); _context.SaveChanges(); user.ID = user1.ID; return(user); }