public IActionResult EditAccount(CustomerTrans model) { if (!ModelState.IsValid) { return(View(model)); } var user = _dbc.Customer.Where(x => x.UserId.Equals(HttpContext.Session.GetInt32("UserId"))).FirstOrDefault(); user.Secret_Qns = model.customer.Secret_Qns; user.Secret_Ans = model.customer.Secret_Ans; user.Uemail = model.customer.Uemail; user.Username = model.customer.Username; user.Pwd = model.customer.Pwd; user.Confirmpwd = model.customer.Pwd; if (user.enabled == true) { user.enabled = true; } else { user.enabled = false; } _dbc.SaveChanges(); return(Redirect("/Account/myAccount/" + user.UserId)); }
public Customer GetCustomerById(int Id) { CustomerDBOps customerdbops = new CustomerDBOps(); //customerdbops.SelectCusotmer(Id); return(CustomerTrans.ConverterCustomer(customerdbops.SelectCusotmer(Id))); }
public IActionResult myAccount(int id) { _logger.LogInformation("The account page has been accessed"); var user = _dbc.Customer.Where(x => x.UserId.Equals(id)).FirstOrDefault(); var creditcard = _dbc.CreditCard.FromSqlRaw($"select * from CreditCard where userid = {id}").ToList(); if (HttpContext.Request.Cookies["user_id"] == "1") { ViewBag.isAdmin = "True"; } var orderHist = _dbc.OrderDetails.Where(x => x.CustomerID.Equals(id)).ToList(); CustomerTrans model = new CustomerTrans(); Customer customer = new Customer(); model.creditcard = creditcard; model.orderHistory = orderHist; customer.UserId = user.UserId; customer.Username = user.Username; customer.Pwd = user.Pwd; customer.Confirmpwd = user.Confirmpwd; customer.Uemail = user.Uemail; customer.Postal_code = user.Postal_code; customer.City = user.City; customer.Phone = user.Phone; customer.Active = user.Active; customer.Secret_Ans = user.Secret_Ans; customer.Secret_Qns = user.Secret_Qns; model.customer = customer; var connectionStringBuilder = new SqliteConnectionStringBuilder(); connectionStringBuilder.DataSource = _webHostEnvironment.ContentRootPath + @"/database.db"; var connection = new SqliteConnection(connectionStringBuilder.ConnectionString); connection.Open(); var selectCmd = connection.CreateCommand(); selectCmd.CommandText = "select * from Products"; var reader = selectCmd.ExecuteReader(); List <Products> models = new List <Products>(); while (reader.Read()) { var items = new Products(); items.ProductId = reader.GetString(0); items.Title = reader.GetString(1); items.Author = reader.GetString(2); items.Genre = reader.GetString(3); items.Price = reader.GetDecimal(4); items.image = GetImageUrlForProduct(reader.GetString(0)); models.Add(items); } reader.Close(); return(View(model)); }
public IActionResult Deactivate(int id, CustomerTrans model, string Confirm) { _logger.LogInformation("The deactivate page has been accessed"); if (Confirm != "Confirm") { ViewBag.notdeactivated = "Not Successful"; HttpContext.Session.SetString("cannot_deactivate", "yes"); return(Redirect("/Account/myAccount/" + model.customer.UserId)); } else { var user = _dbc.Customer.Where(x => x.UserId.Equals(id)).FirstOrDefault(); user.Active = "0"; _dbc.SaveChanges(); HttpContext.Session.Clear(); foreach (var cookie in HttpContext.Request.Cookies) { Response.Cookies.Delete("user_id"); } return(Redirect("/Account/Login")); } }