public string AddDeliveryAddress(AddDeliveryAddressModel model) { try { using (dbContext) { var deliveryAddress = new Delivery { Id = model.Id, City = model.City, Complex = model.Complex, Fullnames = model.Fullnames, isResidential = model.isResidential, PostalCode = model.PostalCode, Province = model.Province, RecipientMobileNo = model.RecipientMobileNo, StreetAddress = model.StreetAddress, Suburb = model.Suburb }; dbContext.Add(deliveryAddress); dbContext.SaveChanges(); return("Succesfully Added !"); } } catch (Exception ex) { return(ex.Message.ToString()); } }
public string CompleteOrder(OrderModel model) { try { using (dbContext) { var order = dbContext.Orders.Find(model.Id); if (order != null) { order.Id = model.Id; order.CartUserId = model.CartUserId; order.OrderDate = model.OrderDate; order.Status = "Delivered"; order.CompletionDate = model.CompletionDate; } dbContext.SaveChanges(); } return($"Order has been delivered succesfully !"); } catch (Exception ex) { return(ex.Message.ToString()); } }
public string RegisterCustomer(CustomerModel model) { try { using (dbContext) { var customer = new Customer { Id = model.Id, Fullnames = model.Fullnames, Username = model.Username, Address = model.Address, EmailAddress = model.EmailAddress, CellNumber = model.CellNumber, Password = model.Password, DateCreated = DateTime.Now, DateOfBirth = model.DateOfBirth }; dbContext.Customers.Add(customer); dbContext.SaveChanges(); return($"Customer {model.Fullnames} successfully created !"); } } catch (Exception ex) { return(ex.Message.ToString()); } }
public string LogTransaction(TransactionModel model) { try { using (dbContext) { var transaction = new Transaction { EndTime = model.EndTime, Status = model.Status, TransactionName = model.TransactionName, StartTime = model.StartTime, Failure = model.Failure, Parameters = model.Parameters, Success = model.Success, TriggeredAction = model.TriggeredAction }; dbContext.Add(transaction); dbContext.SaveChanges(); return("Logged Transaction successfully completed"); } } catch (Exception ex) { return(ex.InnerException.Message); } }
public string Add_SubGroup(SubGroupModel model) { try { using (dbContext) { var subGroup = new SubGroup { SubGroup_Id = model.Id, Name = model.Name, Description = model.Description, GroupId = model.GroupId, CreatedBy = "Prince Lunga", DateCreated = DateTime.Now }; dbContext.SubGroups.Add(subGroup); dbContext.SaveChanges(); return($"Sub-Group {model.Name} successfully added !"); } } catch (Exception ex) { return(ex.Message.ToString()); } }
public string Add_Product(PostProductModel model) { try { using (dbContext) { if ((model.Name != null) && (model.Group != null) && (model.Price != 0)) { var product = new Product { Id = model.Id, Name = model.Name, Description = model.Description, Group = model.Group, SubGroup = model.SubGroup, Image = model.Image, Price = Convert.ToDouble(model.Price.ToString()), Quantity = model.Quantity, Status = "InStock", CreatedBy = "Prince Lunga", DateCreated = DateTime.Now, Discount = model.Discount, Vat = model.Vat }; dbContext.Products.Add(product); dbContext.SaveChanges(); return("Product Successfully Added"); } else { return("Failed to Post when model is null"); } } } catch (Exception ex) { return(ex.Message.ToString()); } }
//Add a product to a shopping using as Id specified as a parameter public CartModel AddToCart(AddToCartModel model) { try { using (dbContext) { if (model.Username != null) { cartItem = dbContext.Carts.SingleOrDefault(c => c.ProductId == model.Id && c.UserCartId == model.Username && c.Status.Equals("Added")); } //Find the product on the cart << << << < HEAD //double productPrice = 0; == == == = >> >> >> > origin / sub_Branch var product = dbContext.Products.Where(x => x.Id == model.Id).SingleOrDefault(); if (cartItem == null) { // Create a new cart item if no cart item exists. cartItem = new Cart { ProductId = model.Id, UserCartId = model.Username, Quantity = 1, Status = "Added", DateCreated = DateTime.Now, Price = product.Price, Discount = 0.00 }; dbContext.Carts.Add(cartItem); } else { // If the item does exist in the cart, // then add one to the quantity. cartItem.Quantity++; cartItem.Price = product.Price; } dbContext.SaveChanges(); }
public CartHistoryModel AddToCartHistory(CartHistoryModel model) { using (dbContext) { if (model != null) { CartHistory history = new CartHistory { CartHistoryId = model.CartHistoryId, ProductId = model.ProductId, UserCartId = model.UserCartId, //Product = model.Product, Quantity = model.Quantity, Price = model.Price, Status = model.Status, DateRecorded = model.DateRecorded }; _ = dbContext.CartHistories.Add(history); _ = dbContext.SaveChanges(); return(model); } } return(model); }
public string AddPayment(PaymentModel model) { try { using (dbContext) { var payment = new Payment { Id = model.Id, Amount = model.Amount, CustomerUsername = model.CustomerUsername, PaymentDate = DateTime.Now }; dbContext.Add(payment); dbContext.SaveChanges(); return("Successfully added payment transaction"); } } catch (Exception) { throw new Exception(); } }