public async Task <IActionResult> Create([Bind("Id,UserName,Password,GroupId,Name,Address,Email,Phone,ProvinceId,DistrictId,CreatedDate,CreatedBy,ModifiedDate,ModifiedBy,Status")] User user) { if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("PhoneNumber,VerificationCode,FullName,NotificationDeviceId,Id,CreationDate,DeletedDate")] User user) { if (ModelState.IsValid) { user.Id = Guid.NewGuid(); _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> Create([Bind("Name,ImageUrl,Id,CreationDate,DeletedDate")] Category category) { if (ModelState.IsValid) { category.Id = Guid.NewGuid(); _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("IsPayed,PaymentUrl,DeliveryAddress,OrderStatus,Id,CreationDate,DeletedDate")] Order order) { if (ModelState.IsValid) { order.Id = Guid.NewGuid(); _context.Add(order); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(order)); }
public IActionResult SaveOrder() //funkcija povlaci sve cart items za ovog usera a nakon toga ih briše, obzirom da je dosao do mogucnosti da Zakljuci narudzbu znaci da su svi preduslovi osigurani da se kreira zapis u tabeli Order { var userid = Int32.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)); var listacart = _order.GetAllCartItemsByUser(userid); var order = new Order { UserID = userid, OrderDate = DateTime.Now, TotalPrice = _order.GetTotalPrice(userid), OrderStatusID = 1, }; _database.Add(order); _database.SaveChanges(); var id = _database.order.ToList().Last().OrderID; //get orderid foreach (var x in listacart) { var item = new OrderDetails { OrderID = id, ProductID = x.ProductID, Quantity = x.Quantity, }; _database.product.Find(x.ProductID).UnitsInStock -= x.Quantity; //obzirom da je ovo neko kupio, taj item se umanjuje za datu kolicinu _database.Add(item); _database.SaveChanges(); } _cart.RemoveAllCartItems(userid); //obzirom da je sve prešlo u orderdetails, briše se sve iz korpe za tog usera Notification nova = new Notification { UserID = userid, Text = "Vaša narudžba (" + id + ") se obrađuje." }; _database.Add(nova); _database.SaveChanges(); return(Redirect("OrderMessage")); }
public IActionResult SaveOrderChanges(EditOrderVM model) { var order = _database.order.Find(model.OrderID); foreach (var x in model.items) { var a = 0; foreach (var y in x.branches) { a += y.Input; _database.branchproduct.FirstOrDefault(a => a.BranchID == y.BranchID && x.ProductID == a.ProductID).UnitsInBranch -= y.Input; } if (a != x.RequiredQuantity) { return(Redirect("/Administration/EditOrder?id=" + model.OrderID + "&again=" + true)); } } order.OrderStatusID = 2; order.OrderStatus = _database.orderstatus.Find(2); order.ShipDate = DateTime.Now; Notification nova = new Notification { UserID = order.UserID, Text = "Vaša narudžba (" + model.OrderID + ") je isporučena." }; Parallel.Invoke(() => Sms("Narudzba <" + model.OrderID + "> je isporucena.")); _database.Add(nova); _database.Add(new AdminActivity { ActivityID = 10, AdminID = Int32.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)), DateOfActivity = DateTime.Now }); _database.SaveChanges(); foreach (var x in model.items) { if (_database.product.Find(x.ProductID).UnitsInStock == 0) { Sms("Proizvod " + _database.product.Find(x.ProductID).ProductName + " (" + x.ProductID + ") vise nije dostupan."); } } return(PartialView("SuccessMessage")); }
public IActionResult AddBranch() { var model = new AddBranchVM { _cities = _context.city.Select(e => new Microsoft.AspNetCore.Mvc.Rendering.SelectListItem { Value = e.CityID.ToString(), Text = e.CityName }).ToList() }; _context.Add(new AdminActivity { ActivityID = 9, AdminID = Int32.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)), DateOfActivity = DateTime.Now }); _context.SaveChanges(); return(View(model)); }
public IActionResult AddProduct(int ProductID) { Product temp; if (ProductID != 0) { temp = _database.product.Find(ProductID); } else { temp = new Product(); } var data = new AddOrUpdateProductVM { ProductID = temp.ProductID, ProductNumber = temp.ProductNumber, SubCategoryID = temp.SubCategoryID, Subcategories = _database.subcategory.Select(s => new SelectListItem { Value = s.SubCategoryID.ToString(), Text = s.SubCategoryName }).ToList(), ManufacturerID = temp.ManufacturerID, Manufacturers = _database.manufacturer.Select(s => new SelectListItem { Value = s.ManufacturerID.ToString(), Text = s.ManufacturerName }).ToList(), ProductName = temp.ProductName, //Image = temp.ImageUrl, Description = temp.Description, UnitPrice = temp.UnitPrice, UnitsInStock = temp.UnitsInStock }; _database.Add(new AdminActivity { ActivityID = 1, AdminID = Int32.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)), DateOfActivity = DateTime.Now }); _database.SaveChanges(); return(View(data)); }
public void AddToCart(int productid, int userid, int q) { Cart singlerecord = _database.cart.SingleOrDefault(u => u.UserID == userid && u.ProductID == productid); Product product = _database.product.Find(productid); if (singlerecord != null) { singlerecord.Quantity += q; singlerecord.TotalPrice = (singlerecord.Quantity + q) * product.UnitPrice; } else { Cart newrecord = new Cart { UserID = userid, ProductID = productid, Quantity = q, TotalPrice = product.UnitPrice * q }; _database.Add(newrecord); } _database.SaveChanges(); }
public void AddToCart(int productid, int userid, int q) { //var userid = Int32.Parse(User.FindFirstValue(ClaimTypes.NameIdentifier)); Cart singlerecord = _database.cart.SingleOrDefault(u => u.UserID == userid && u.ProductID == productid); Product product = _database.product.Find(productid); if (singlerecord != null) { singlerecord.Quantity += q; singlerecord.TotalPrice = (singlerecord.Quantity + q) * product.UnitPrice; } else { Cart newrecord = new Cart { UserID = userid, ProductID = productid, Quantity = q, TotalPrice = product.UnitPrice * q }; _database.Add(newrecord); } _database.SaveChanges(); }
public void AddBranch(Branch branch) { _context.Add(branch); _context.SaveChanges(); }
public void AddProduct(Product p) { baza.Add(p); baza.SaveChanges(); }
public void AddCategory(Category category) { _context.Add(category); _context.SaveChanges(); }