public IActionResult PurchaseItem(Items item) { ShopDBContext db = new ShopDBContext(); Users founduser = new Users(); Items foundItem = new Items(); PurchasedItems foundPurchasedItem = new PurchasedItems(); foreach (Users u in db.Users) { if (u.Id == HttpContext.Session.GetInt32("current")) { founduser = u; } } foreach (Items i in db.Items) { if (i.ProductName == item.ProductName) { foundItem = i; } } foreach (PurchasedItems d in db.PurchasedItems) { if (d.ProductName == item.ProductName && d.UserId == founduser.Id) { foundPurchasedItem = d; } } if (founduser.Funds > foundItem.Price) { founduser.Funds -= foundItem.Price; foundItem.Quantity -= 1; PurchasedItems purchasedItem = new PurchasedItems() { UserId = founduser.Id, ProductName = foundItem.ProductName, Description = foundItem.Description, ItemType = foundItem.ItemType, Quantity = 1 }; UserItems useritem = new UserItems() { ItemId = foundItem.ProductName, UserId = founduser.Id, }; db.Add(useritem); if (foundPurchasedItem.ProductName != null) { foundPurchasedItem.Quantity += 1; } else { db.Add(purchasedItem); } db.SaveChanges(); return(View("Shop", db)); } else { return(InsufficientFunds(founduser.Funds.ToString(), foundItem.Price.ToString())); } }
public void CreateProduct(Product product) { using (var dbc = new ShopDBContext()) { dbc.Add(product); dbc.SaveChanges(); } }
public IActionResult AddUser(Users user) { ShopDBContext db = new ShopDBContext(); db.Add(user); db.SaveChanges(); return(View(user)); }
public IActionResult MakeNewUser(Users u) { //use this object to access db data ShopDBContext db = new ShopDBContext(); db.Add(u); db.SaveChanges(); return(View(u)); }
public IActionResult Create([Bind("Id,ItemName,ItemDescription,Quantity,Price")] Items items) { if (ModelState.IsValid) { _context.Add(items); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(items)); }
public IActionResult MakeNewUser(Users user) { ShopDBContext db = new ShopDBContext(); db.Add(user); db.SaveChanges(); return(View("Registered", user)); }
public async Task <IActionResult> Create([Bind("Id,CategoryName")] Category category) { if (ModelState.IsValid) { _context.Add(category); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(category)); }
public async Task <IActionResult> Create([Bind("UserItemId,UserId,ItemId")] UserItems userItems) { if (ModelState.IsValid) { _context.Add(userItems); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(userItems)); }
public async Task <IActionResult> OnPostAsync(string returnUrl = null) { returnUrl = returnUrl ?? Url.Content("~/"); ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = new IdentityUser { UserName = Input.Email, Email = Input.Email, PhoneNumber = Input.Phone }; Users ShopUser = new Users { Email = Input.Email, UserName = Input.UserName, FirstName = Input.FirstName, LastName = Input.LastName, Phone = Input.Phone }; var result = await _userManager.CreateAsync(user, Input.Password); if (result.Succeeded) { _logger.LogInformation("User created a new account with password."); var code = await _userManager.GenerateEmailConfirmationTokenAsync(user); code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code)); var callbackUrl = Url.Page( "/Account/ConfirmEmail", pageHandler: null, values: new { area = "Identity", userId = user.Id, code = code }, protocol: Request.Scheme); await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>."); if (_userManager.Options.SignIn.RequireConfirmedAccount) { return(RedirectToPage("RegisterConfirmation", new { email = Input.Email })); } else { await _signInManager.SignInAsync(user, isPersistent : false); result = await _userManager.AddToRoleAsync(user, "User"); _context.Add(ShopUser); _context.SaveChanges(); return(LocalRedirect(returnUrl)); } } foreach (var error in result.Errors) { ModelState.AddModelError(string.Empty, error.Description); } } // If we got this far, something failed, redisplay form return(Page()); }
public async Task <IActionResult> Create([Bind("Id,CategoryId,ProductName,ProductPrice,InsertedDate,UpdatedDate")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "CategoryName", product.CategoryId); return(View(product)); }
public IActionResult Create([Bind("Id,UserName,FirstName,LastName,Email,Phone,UserPassword,ConfirmPassword,Points,Notifications")] Users users) { if (ModelState.IsValid) { IdentityUser iUser = new IdentityUser() { UserName = users.Email, Email = users.Email, NormalizedEmail = users.Email.ToUpper(), PhoneNumber = users.Phone }; _identityContext.Add(iUser); _identityContext.SaveChanges(); _context.Add(users); _context.SaveChanges(); return(RedirectToAction(nameof(Index))); } return(View(users)); }
public IActionResult Resister(User model) { using (var db = new ShopDBContext()) { var user = db.Users.FirstOrDefault(u => u.UserID.Equals(model.UserID)); if (user != null) { ModelState.AddModelError("SignError", "이미 등록되있는 아이디입니다."); return(View()); } else { db.Add(model); db.SaveChanges(); return(RedirectToAction("Shop", "Home")); } } }
public IActionResult BuyResult(int ID) //ID for item { var viewModel = new BuyResultViewModel(); viewModel.Funds = _user.theUser.Funds; viewModel.CurrentUserID = _user.theUser.UserID; var userItem = new UserItemsDAL(); userItem.UserId = viewModel.CurrentUserID; double price = 0; foreach (var item in _shopDBContext.Items.ToList()) { if (item.ItemID == ID) { price = item.Price; userItem.ItemId = item.ItemID; userItem.Name = item.Name; userItem.Description = item.Description; userItem.Quantity = item.Quantity; userItem.Price = item.Price; } } _shopDBContext.Add(userItem); _shopDBContext.SaveChanges(); bool enoughCash = false; foreach (var user in _shopDBContext.Users.ToList()) { if (user.UserID == viewModel.CurrentUserID) { if (viewModel.Funds > price) { enoughCash = true; user.Funds = user.Funds - price; _shopDBContext.SaveChanges(); viewModel.Funds = user.Funds; _user.theUser.Funds = user.Funds; } } } var errorModel = new ErrorPageViewModel(); errorModel.UserFunds = viewModel.Funds; //var shopModel = new ShopViewModel(); //shopModel.CurrentUserID = _user.theUser.UserID; //shopModel.Funds = _user.theUser.Funds; if (enoughCash) { return(View(viewModel)); } else { return(View("ErrorPage", errorModel)); } }
public void AddOrders(Orders obj) { _context.Add(obj); _context.SaveChanges(); }
public void AddItem(Items obj) { _context.Add(obj); _context.SaveChanges(); }
public void Add(Orders item) { _context.Add(item); _context.SaveChanges(); }
public void AddItems(Orders order) { _context.Add(order); _context.SaveChanges(); }