public void Activate(int id) { Product product = db.Products.Find(id); product.Enable = !product.Enable; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); }
public void Activate(int id) { Category category = db.Categories.Find(id); category.Enable = !category.Enable; db.Entry(category).State = EntityState.Modified; db.SaveChanges(); }
public void Activate(int id) { Article article = db.Articles.Find(id); article.Enable = !article.Enable; db.Entry(article).State = EntityState.Modified; db.SaveChanges(); }
public void Insert(Address entity) { if (entity == null) { throw new ArgumentNullException("entity"); } context.Addresses.Add(entity); context.SaveChanges(); }
public void Insert(FeatureValue entity) { if (entity == null) { throw new ArgumentNullException("entity"); } context.FeatureValues.Add(entity); context.SaveChanges(); }
public void Insert(BasketItem entity) { if (entity == null) { throw new ArgumentNullException("entity"); } context.BasketItems.Add(entity); context.SaveChanges(); }
public PartialViewResult Create([Bind(Include = "RegulationID,Rule")] Regulation regulation) { if (ModelState.IsValid) { db.Regulations.Add(regulation); db.SaveChanges(); return(PartialView("~/Views/Admin/Regulations.cshtml", db.Regulations.ToList())); } return(PartialView()); }
public PartialViewResult Create([Bind(Include = "OrderPaymentID,Name,Price")] OrderPayment orderPayment) { if (ModelState.IsValid) { db.OrderPayments.Add(orderPayment); db.SaveChanges(); return(PartialView("~/Views/Admin/OrderPayments.cshtml", db.OrderPayments.ToList())); } return(PartialView()); }
public ActionResult Create([Bind(Include = "ContactID,Telephone,Address,AccountNumber,Email,WeekOpenTime,SaturdayOpenTime,SundayOpenTime,GoogleMapUrl")] Contact contact) { if (ModelState.IsValid) { db.Contacts.Add(contact); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(contact)); }
public ActionResult Create([Bind(Include = "OrderProductHistoryID,OrderProductID,Price")] OrderProductHistory orderProductHistory) { if (ModelState.IsValid) { db.OrderProductHistory.Add(orderProductHistory); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.OrderProductID = new SelectList(db.OrderProducts, "OrderProductID", "userID", orderProductHistory.OrderProductID); return(View(orderProductHistory)); }
public ActionResult Create([Bind(Include = "UserID,UserRoleID,Email,Name,Surname,Password,Address,Telephone")] User user) { if (ModelState.IsValid) { db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserRoleID = new SelectList(db.UserRoles, "UserRoleID", "Name", user.UserRoleID); return(View(user)); }
public async Task <IActionResult> PlaceOrder(Guid customerId, Guid kitId) { var currentCustomer = _context.Customers.FirstOrDefault(c => c.Id == customerId); if (currentCustomer == null) { throw new Exception($"No customer with id {customerId}"); } var selectedKit = _context.Kits.FirstOrDefault(x => x.Id == kitId); if (currentCustomer == null) { throw new Exception($"No kit with id {kitId}"); } var currentOrder = _context.Orders .Include(o => o.OrderItems) .FirstOrDefault(x => x.CustomerId == customerId && x.Status == OrderStatus.Active); if (currentOrder == null) { currentOrder = new Order { CustomerId = currentCustomer.Id, OrderItems = new List <OrderItem>(), Status = OrderStatus.Active, // Invoice = new Invoice() //{ // Amount = 1000, //} }; } var anyItemInCategory = currentOrder.OrderItems.Any(x => x.Kit.CategoryId == selectedKit.CategoryId); if (anyItemInCategory) { throw new Exception($"Item of category {selectedKit.Category.Name} already selected"); } currentOrder.OrderItems.Add(new OrderItem() { KitId = selectedKit.Id }); _context.Orders.Add(currentOrder); var result = _context.SaveChanges(); return(View()); }
public async Task <ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { Name = model.Name, Surname = model.Surname, Telephone = model.Telephone, UserName = model.Email, Email = model.Email, Address = model.Address }; var result = UserManager.Create(user, model.Password); if (result.Succeeded) { var con = new ApplicationDbContext(); var roleResult = UserManager.AddToRole(user.Id, "Klient"); User userX = new User { UserID = user.Id, Email = user.Email, UserRoleID = 3, Name = model.Name, Surname = model.Surname, Address = model.Address, Telephone = model.Telephone.ToString(), Agreement = true }; db.Users.Add(userX); db.SaveChanges(); // Comment the following line to prevent log in until the user is confirmed. //await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); string callbackUrl = await SendEmailConfirmationTokenAsync(user.Id, "Potwierdź swoje konto"); ViewBag.Message = "Na podany adres email '" + user.Email + "' został wysłany link służący do aktywacji konta w systemie."; // For local debug only //ViewBag.Link = callbackUrl; return(View("Info")); //return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return(View(model)); }
public void AddOneProductToCart(int?id, int quantity = 1) { var userId = User.Identity.GetUserId(); if (id == null) { } Product product = db.Products.Find(id); if (product.Quantity < quantity) { quantity = product.Quantity; } OrderProduct orderProduct = db.OrderProducts.Where(y => y.ProductOrderStateID == 1).FirstOrDefault(x => x.Product.ProductID == id); if (orderProduct == null) { Order orderX = db.Orders.Where(y => y.OrderStateID == 1).FirstOrDefault(x => x.UserID == userId); if (orderX == null) { Order order = new Order { UserID = userId, OrderStateID = 1, OrderPaymentID = 1, OrderSupplyID = 1 }; db.Orders.Add(order); db.SaveChanges(); } Order orderY = db.Orders.Where(y => y.OrderStateID == 1).FirstOrDefault(x => x.UserID == userId); int orderId = orderY.OrderID; OrderProduct OP = new OrderProduct { Product = product, Quantity = quantity, ProductOrderStateID = 1, OrderID = orderId, userID = userId }; OP.Suma = OP.Product.Price * OP.Quantity; db.OrderProducts.Add(OP); db.SaveChanges(); } else { orderProduct.Quantity += quantity; orderProduct.Suma = orderProduct.Product.Price * orderProduct.Quantity; db.Entry(orderProduct).State = EntityState.Modified; db.SaveChanges(); } product.Quantity -= quantity; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); }
public ActionResult Index() { var today = DateTime.Now.Date; double dailySum = 0; int ordersSum = 0; int productsSum = 0; int realised = 0; var orders = db.Orders.Include(o => o.OrderPayment).Include(o => o.OrderState).Include(o => o.OrderSupply).Include(o => o.User).Where(x => x.OrderStateID != 1); if (orders.Any()) { foreach (var x in orders.Where(x => DateTime.Compare(x.IncomingDate ?? DateTime.MinValue, today) > 0)) { dailySum += x.Suma; ordersSum++; if (x.OrderStateID == 3) { realised++; } } Raport raport = db.Raports.Where(x => (DateTime.Compare(x.Date, today) == 0)).FirstOrDefault(); var order = orders.Where(x => (DateTime.Compare(x.IncomingDate ?? DateTime.MinValue, today) > 0)).FirstOrDefault(); if (order != null) { int orderId = order.OrderID; foreach (var x in db.OrderProducts.Where(x => x.OrderID == orderId)) { productsSum += x.Quantity; } if (raport == null) { Raport raportX = new Raport { Date = today, DailyRevenue = dailySum, ProductsQuantity = productsSum, OrdersQuantity = ordersSum, Realised = realised }; db.Raports.Add(raportX); db.SaveChanges(); } else { raport.DailyRevenue = dailySum; raport.ProductsQuantity = productsSum; raport.OrdersQuantity = ordersSum; raport.Realised = realised; db.Entry(raport).State = EntityState.Modified; db.SaveChanges(); } return(View(db.Raports)); } else { if (raport == null) { Raport raportX = new Raport { Date = today, DailyRevenue = dailySum, ProductsQuantity = productsSum, OrdersQuantity = ordersSum, Realised = realised }; db.Raports.Add(raportX); db.SaveChanges(); } } } return(View(db.Raports)); }