public IActionResult Login(LoginModel model) { try { LoginModel x = new LoginModel(); var customers = _repo.GetAllCustomer(); var c = customers.Where(a => a.Username == model.Username && a.Pass == model.Pass).FirstOrDefault(); if (c != null) { x.logged = true; } else { x.logged = false; } _logger.LogInformation("Home Controller: PostLogin"); TempData["Logged"] = c.Username; return(View(x)); } catch { model.errorMessage = "There is no user name or wrong pass"; return(View(model)); } }
public IActionResult AddCustomer(ViewCustomerModel m) { if (!ModelState.IsValid) { return(View()); } try { _logger.LogInformation("Customer Controller: PostAddCustomer"); if (Regex.IsMatch(m.Customer.FirstName, @"^[a-zA-Z]+$") || Regex.IsMatch(m.Customer.LastName, @"^[a-zA-Z]+$")) { var x = _repo.GetAllCustomer().Where(x => x.Username == m.Customer.Username).FirstOrDefault(); if (x != null) { m.errorMessage = "Can not add Customer due to error. There is already a user with the username"; return(View(m)); } else { TempData["Logged"] = m.Customer.Username; _repo.AddCustomer(m.Customer); } } if (TempData["NotLogged"].ToString() == "true") { return(RedirectToAction("FinishOrder", "AddToCart")); } else { return(View(m)); } }catch { m.errorMessage = "Something Went Wrong with adding a customer. Please contact Your Admin."; return(View()); } }
public IActionResult FinishOrder() { _logger.LogInformation("AddToCart Controller: GetFinishOrder"); ViewOrderDetailsModel od = new ViewOrderDetailsModel(); od.Product = DeserObjectOrderDetail(TempData["OrderDetail"].ToString()); od.Date = DateTime.Now; od.store = DeserObjectStore(TempData["Store"].ToString()); Order o = new Order(); o.Product = od.Product; o.Store = od.store; try { var allC = _repo.GetAllCustomer().Where(c => c.Username == TempData.Peek("Logged").ToString()).FirstOrDefault(); o.Customer = allC; _repo.AddOrder(o); var allOrder = _repo.GetAllOrders().Count(); foreach (Product x in od.Product.Keys) { _repo.AddOrderDetail(od.Product[x], x.ID, allOrder); } foreach (Product x in od.Product.Keys) { var item = od.store.ItemInventory.Where(a => a.Key.ID == x.ID).FirstOrDefault(); _repo.MakeInventoryChanges(od.store.StoreID, x.ID, item.Value); } return(View(od)); } catch { return(RedirectToAction("AddCustomer", "Customer")); } }