public List<Customer> getAll() { var cust = new Customer() { id = 1, firstname = "Gunnar", lastname = "Hansen", address = "Golia", email = "*****@*****.**", postalarea = "Gollie", postalcode = "1232", phonenumber = "94499449", password = "******" }; var cust2 = new Customer() { id = 2, firstname = "Frodo", lastname = "Baggins", address = "Mordor", email = "*****@*****.**", postalarea = "Hobbitland", postalcode = "2322", phonenumber = "94499433", password = "******" }; List<Customer> custList = new List<Customer>(); custList.Add(cust); custList.Add(cust2); return custList; }
public Customer getCustomer(int id) { try { var db = new DatabaseContext(); Customers cust = (Customers)db.Customers.FirstOrDefault(c => c.Id == id); Customer customer = new Customer(); customer.id = cust.Id; customer.firstname = cust.Firstname; customer.lastname = cust.Lastname; customer.phonenumber = cust.Phonenumber; customer.email = cust.Email; customer.address = cust.Address; customer.hashpassword = cust.Password; customer.admin = cust.Admin; customer.postalarea = getPostalarea(cust.PostalareasId); customer.postalcode = normalizePostalcode(cust.PostalareasId); return customer; } catch(Exception e) { writeToFile(e); return null; } }
public List<Customer> GetAllCustomers() { var customerList = new List<Customer>(); try { using (var db = new TankshopDbContext()) { var dbCustomers = db.Customers.ToList(); foreach (var c in dbCustomers) { var p = db.People.Find(c.Email); var customer = new Customer() { Email = p.Email, Firstname = p.Firstname, Lastname = p.Lastname, Address = p.Address, Postal = new Postal { Zipcode = p.Zipcode, City = p.Postal.City }, CustomerId = c.CustomerId, Orders = c.Orders.Select(o => new Order() { CustomerId = o.CustomerId, Date = o.Date, OrderId = o.OrderId, Orderlines = o.Orderlines.Select(l => new Orderline() { Count = l.Count, OrderId = l.OrderId, OrderlineId = l.OrderlineId, ProductId = l.ProductId, ProductName = l.Product.Name, ProductPrice = l.Product.Price }).ToList() }).ToList() }; customerList.Add(customer); } return customerList; } } catch (Exception) { return customerList; } }
public CustomerRepoStub() { orderlineModel = new Orderline() { Count = 1, OrderId = 1, OrderlineId = 1, ProductId = 1, ProductName = "Tank", ProductPrice = 500000 }; orderlineModels = new List<Orderline>(); orderlineModels.Add(orderlineModel); orderlineModels.Add(orderlineModel); orderlineModels.Add(orderlineModel); orderModel = new Order() { CustomerId = 1, Date = new DateTime(2015, 1, 1), OrderId = 1, Orderlines = orderlineModels }; orderModels = new List<Order>(); orderModels.Add(orderModel); orderModels.Add(orderModel); orderModels.Add(orderModel); customerModel = new Customer() { CustomerId = 1, Email = "*****@*****.**", Firstname = "Ole", Lastname = "Olsen", Address = "Persveien 5", Postal = new Postal { Zipcode = "0123", City = "Oslo" }, Orders = orderModels }; }
public Customer findCustomer(String email) { var cust = new Customer() { id = 1, firstname = "Gunnar", lastname = "Honsen", address = "Golia", email = "*****@*****.**", postalarea = "Gollie", postalcode = "1232", phonenumber = "94499449", password = "******" }; return cust; }
public List<Customer> getResult(string searchString) { var cust = new Customer() { id = 1, firstname = "Gunnar", lastname = "Hinsen", address = "Golia", email = "*****@*****.**", postalarea = "Gollie", postalcode = "1232", phonenumber = "94499449", password = "******" }; List<Customer> custList = new List<Customer>(); custList.Add(cust); return custList; }
public bool SetRole(string email, Role role, bool isRole) { using (var db = new TankshopDbContext()) { try { if (role == Role.Admin) { var dbAdmin = db.Admins.Find(email); if (isRole) { if (dbAdmin == null) { var newAdmin = new Admin() { Email = email }; db.Admins.Add(newAdmin); } } else { db.Admins.Remove(dbAdmin); } } if (role == Role.Customer) { var dbCustomer = db.Customers.Find(email); if (isRole) { if (dbCustomer == null) { var newCustomer = new Nettbutikk.Model.Customer() { Email = email }; db.Customers.Add(newCustomer); } } else { db.Customers.Remove(dbCustomer); } } //db.SaveChanges(); return true; } catch (Exception) { return false; } } }
public bool AddPerson(PersonModel person, Role role, string password) { var email = person.Email; var newPerson = new Person() { Email = email, Firstname = person.Firstname, Lastname = person.Lastname, Address = person.Address, Zipcode = person.Zipcode, }; using (var db = new TankshopDbContext()) { using (var transaction = db.Database.BeginTransaction()) { try { var personPostal = db.Postals.Find(person.Zipcode); if (personPostal == null) { personPostal = new Postal() { Zipcode = person.Zipcode, City = person.City }; } personPostal.People.Add(newPerson); newPerson.Postal = personPostal; // Create email / password - combination var existingCredentials = db.Credentials.Find(email); if (existingCredentials != null) return false; var passwordHash = CreateHash(password); var newCredentials = new Credential() { Email = email, Password = passwordHash }; db.Credentials.Add(newCredentials); // Set Customer / AdminId int AdminId = 0, CustomerId = 0; if (role == Role.Admin) { var dbAdmin = db.Admins.FirstOrDefault(a => a.Email == email); if (dbAdmin == null) { dbAdmin = new Admin() { Email = email }; db.Admins.Add(dbAdmin); } AdminId = dbAdmin.AdminId; } if (role == Role.Customer) { var dbCustomer = db.Customers.FirstOrDefault(c => c.Email == email); if (dbCustomer == null) { dbCustomer = new Nettbutikk.Model.Customer() { Email = email }; db.Customers.Add(dbCustomer); } CustomerId = dbCustomer.CustomerId; } db.People.Add(newPerson); db.SaveChanges(); transaction.Commit(); return true; } catch (Exception) { transaction.Rollback(); return false; } } } }
public bool update(int id, Customer updateUser, int adminid) { var db = new DatabaseContext(); try { Customers cust = db.Customers.FirstOrDefault(u => u.Id == id); cust.Firstname = updateUser.firstname; cust.Lastname = updateUser.lastname; cust.Email = updateUser.email; cust.Phonenumber = updateUser.phonenumber; cust.Address = updateUser.address; cust.PostalareasId = Convert.ToInt16(updateUser.postalcode); var existPostalcode = db.Postalareas.Find(Convert.ToInt16(updateUser.postalcode)); if (existPostalcode == null) { var newPostalarea = new Postalareas() { PostalareasId = Convert.ToInt16(updateUser.postalcode), Postalarea = updateUser.postalarea }; cust.Postalareas = newPostalarea; } db.SaveChanges(adminid); return true; } catch (Exception e) { writeToFile(e); return false; } }
public Customer findUser(String email) { try { var db = new DatabaseContext(); Customers userFound = db.Customers.FirstOrDefault(u => u.Email == email); Customer c = new Customer(); c.id = userFound.Id; c.firstname = userFound.Firstname; c.lastname = userFound.Lastname; c.email = userFound.Email; c.phonenumber = userFound.Phonenumber; c.postalcode = normalizePostalcode(userFound.PostalareasId); c.postalarea = db.Postalareas.Find(userFound.PostalareasId).Postalarea; c.address = userFound.Address; c.hashpassword = userFound.Password; c.admin = true; return c; } catch(Exception e) { writeToFile(e); return null; } }
public ActionResult CustomerDetails(CustomerDetail cd) { if (!isAdmin()) { return RedirectToAction("LogIn", "Main"); } bool b = false; bool eouaoae = ModelState.IsValid; if (ModelState.IsValid) { Customer a = (Customer)Session["loggedInUser"]; Customer c = new Customer(); c.firstname = cd.firstname; c.lastname = cd.lastname; c.address = cd.address; c.email = cd.email; c.phonenumber = cd.phonenumber; c.postalarea = cd.postalarea; c.postalcode = cd.postalcode; b = _customerbll.update(cd.id, c, a.id); if (b) return Json(new { success = true, message = "Endringene ble lagret", redirect = "/Customer/ListCustomers/" }); return Json(new { success = false, message = "Noe gikk galt, endringene ble ikke lagret" }); } return Json(new { success = false, message = "Feil i validering" }); }
public bool update(int id, Customer c, int adminid) { return _customer.update(id,c, adminid); }
public Customer findUser(String email) { var cust = new Customer() { id = 1, email = "*****@*****.**", hashpassword = System.Security.Cryptography.SHA256.Create().ComputeHash(System.Text.Encoding.ASCII.GetBytes("konge")), admin = true }; return cust; }
public Customer getCustomer(int id) { var cust = new Customer(); if (id == 1) { cust = new Customer() { id = 1, firstname = "Gunnar", lastname = "Hansen", address = "Golia", email = "*****@*****.**", postalarea = "Gollie", postalcode = "1232", phonenumber = "94499449", password = "******" }; } else if (id == 2) { cust = new Customer() { id = 2, firstname = "Frodo", lastname = "Baggins", address = "shire", email = "*****@*****.**", postalarea = "hobbittown", postalcode = "1232", phonenumber = "94499449", password = "******" }; } else { cust = new Customer() { id = id, firstname = "Gunnar", lastname = "Hansen", address = "Golia", email = "*****@*****.**", postalarea = "Gollie", postalcode = "1232", phonenumber = "94499449", password = "******" }; } return cust; }
public bool update(int id, Customer updateUser, int adminid) { return false; }
public Customer GetCustomer(int customerId) { if (customerId == 0) { var customer = new Customer() { Email = "" }; return customer; } else { return new Customer() { Email = "*****@*****.**", Firstname = "Test", Lastname = "Test", Address = "Test", Postal = new Postal { Zipcode = "1234", City = "Test" }, CustomerId = 1 }; } }