public List<OrderModel> findOrders(CustomerModel customerModel) { if (customerModel.customerID < 0) return null; var list = new List<OrderModel>(); list.Add(find(1)); list.Add(find(1)); list.Add(find(1)); list.Add(find(1)); return list; }
public CustomerModel find(string email) { if (email == "") return null; var customerModel = new CustomerModel(); customerModel.firstName = "Ola"; customerModel.lastName = "Nordmann"; customerModel.payAdress = "Osloveien 1"; customerModel.payProvince = "Oslo"; customerModel.payZipcode = "1234"; customerModel.phone = "12345678"; customerModel.province = "Oslo"; customerModel.sameAdresses = true; customerModel.zipCode = "1234"; customerModel.adress = "Osloveien 1"; return customerModel; }
public void AllCustomersTestOK() { //Arrange var controller = new AdminCustomerController(new CustomerBLL(new CustomerDALStub()), new LoggingBLL(new LoggingDALStub())); var list = new List<CustomerModel>(); var customerModel = new CustomerModel(); customerModel.customerID = 1; customerModel.firstName = "Ola"; customerModel.lastName = "Nordmann"; customerModel.payAdress = "Osloveien 1"; customerModel.payProvince = "Oslo"; customerModel.payZipcode = "1234"; customerModel.phone = "12345678"; customerModel.province = "Oslo"; customerModel.sameAdresses = true; customerModel.zipCode = "1234"; customerModel.adress = "Osloveien 1"; list.Add(customerModel); list.Add(customerModel); list.Add(customerModel); list.Add(customerModel); //Act var result = (ViewResult)controller.AllCustomers(); var resultList = (List<CustomerModel>)result.Model; //Assert Assert.AreEqual(list.Count, resultList.Count); Assert.AreEqual(result. ViewName, ""); for(int i = 0; i < resultList.Count; i++) { Assert.AreEqual(resultList[i].adress, list[i].adress); Assert.AreEqual(resultList[i].customerID, list[i].customerID); Assert.AreEqual(resultList[i].email, list[i].email); Assert.AreEqual(resultList[i].firstName, list[i].firstName); Assert.AreEqual(resultList[i].lastName, list[i].lastName); Assert.AreEqual(resultList[i].password, list[i].password); Assert.AreEqual(resultList[i].payAdress, list[i].payAdress); Assert.AreEqual(resultList[i].payProvince, list[i].payProvince); Assert.AreEqual(resultList[i].payZipcode, list[i].payZipcode); Assert.AreEqual(resultList[i].phone, list[i].phone); Assert.AreEqual(resultList[i].sameAdresses, list[i].sameAdresses); Assert.AreEqual(resultList[i].zipCode, list[i].zipCode); Assert.AreEqual(resultList[i].province, list[i].province); } }
public ActionResult createUser(CustomerModel newCustomer) { if (!ModelState.IsValid) return View(); var userModel = _userBLL.get(newCustomer.email); if (userModel != null)//tester om en bruker med samme epost finnes fra før { ModelState.AddModelError("", "Eposten du prøver å registrere finnes allerede. Vennligst benytt en annen adresse"); _loggingBLL.logToUser("Prøvde å registrere seg med eksisterende epost: " + userModel.username, (CustomerModel)Session[CUSTOMER]); return View(newCustomer); } if (!_customerBLL.add(newCustomer))//registrerer ny customer { ModelState.AddModelError("", "Feil ved registrering av bruker"); _loggingBLL.logToUser("Fikk en feil ved registrering av brukernavn: " + newCustomer.email, (CustomerModel)Session[CUSTOMER]); return View(newCustomer); } userModel = new UserModel(); userModel.username = newCustomer.email; userModel.passwordHash = getHash(newCustomer.password); userModel.ID = newCustomer.customerID; if (!_userBLL.add(userModel))//registrerer ny user { ModelState.AddModelError("", "Feil ved registrering av bruker"); _loggingBLL.logToUser("Fikk en feil ved registrering av brukernavn: " + userModel.username, (CustomerModel)Session[CUSTOMER]); return View(newCustomer); } _loggingBLL.logToUser("Opprettet bruker: " + newCustomer.email, (CustomerModel)Session[CUSTOMER]); _loggingBLL.logToDatabase("Bruker lagt til i database: " + newCustomer.email); return RedirectToAction("Loginview", "Security", new { area = "" }); }
public void EditTestPostFalse() { //Arrange var controller = MockHttpSession.getMoqAdminCustomerController(); var customerModel = new CustomerModel(); customerModel.customerID = -1; customerModel.firstName = ""; customerModel.lastName = "Nordmann"; customerModel.payAdress = "Osloveien 1"; customerModel.payProvince = "Oslo"; customerModel.payZipcode = "1234"; customerModel.phone = "12345678"; customerModel.province = "Oslo"; customerModel.sameAdresses = true; customerModel.zipCode = "1234"; customerModel.adress = "Osloveien 1"; //Act controller.Session["tempCID"] = 1; controller.Session["Employee"] = new EmployeeModel(); var result = (ViewResult)controller.Edit(customerModel); //Assert Assert.AreEqual(result.ViewName, ""); }
public void EditTestOK() { //Arrange var context = new Mock<ControllerContext>(); var session = new Mock<HttpSessionStateBase>(); context.Setup(m => m.HttpContext.Session).Returns(session.Object); var controller = new AdminCustomerController(new CustomerBLL(new CustomerDALStub()), new LoggingBLL(new LoggingDALStub())); controller.ControllerContext = context.Object; var customerModel = new CustomerModel(); customerModel.customerID = 1; customerModel.firstName = "Ola"; customerModel.lastName = "Nordmann"; customerModel.payAdress = "Osloveien 1"; customerModel.payProvince = "Oslo"; customerModel.payZipcode = "1234"; customerModel.phone = "12345678"; customerModel.province = "Oslo"; customerModel.sameAdresses = true; customerModel.zipCode = "1234"; customerModel.adress = "Osloveien 1"; //Act var result = (ViewResult)controller.Edit(1); var resultModel = (CustomerModel)result.Model; //Assert Assert.AreEqual(result.ViewName, ""); Assert.AreEqual(resultModel.adress, customerModel.adress); Assert.AreEqual(resultModel.customerID, customerModel.customerID); Assert.AreEqual(resultModel.email, customerModel.email); Assert.AreEqual(resultModel.firstName, customerModel.firstName); Assert.AreEqual(resultModel.lastName, customerModel.lastName); Assert.AreEqual(resultModel.password, customerModel.password); Assert.AreEqual(resultModel.payAdress, customerModel.payAdress); Assert.AreEqual(resultModel.payProvince, customerModel.payProvince); Assert.AreEqual(resultModel.payZipcode, customerModel.payZipcode); Assert.AreEqual(resultModel.phone, customerModel.phone); Assert.AreEqual(resultModel.sameAdresses, customerModel.sameAdresses); Assert.AreEqual(resultModel.zipCode, customerModel.zipCode); Assert.AreEqual(resultModel.province, customerModel.province); }
public static bool editCustomer(CustomerModel customerModel) { var customerBLL = new CustomerBLL(); customerModel.firstName="Trond"; customerModel.email = "[email protected]ønning"; customerModel.adress = "Tronnoland"; return customerBLL.update(customerModel); }
public static CustomerModel createCustomer() { var customer = new CustomerModel(); customer.firstName = "Ola"; customer.lastName = "Nordmann"; customer.password = "******"; customer.passwordVerifier = customer.password; customer.payAdress = "Bætaveien 2"; customer.payZipcode = "1234"; customer.payProvince = "Bætaland"; customer.adress = customer.payAdress; customer.province = customer.payProvince; customer.zipCode = customer.payZipcode; customer.email = "*****@*****.**"; customer.phone = "12345678"; return customer; }
public ActionResult editAccountView(CustomerModel customerModel) { customerModel.customerID = getActiveUserID(); var userModel = _userBLL.get(customerModel.customerID);//henter ut user modellen userModel.username = customerModel.email; if (customerModel.password != null)//tester om passord skal endres { userModel.passwordHash = getHash(customerModel.password); } if (!_userBLL.update(userModel))//registrerer endinger i user { ModelState.AddModelError("", "Epost finnes fra før"); return RedirectToAction("editAccountView"); } if (!_customerBLL.update(customerModel))//registrerer endring i customer { ModelState.AddModelError("", "Feil ved registrering av data"); _loggingBLL.logToUser("Fikk en feil ved endring av data på bruker.", (CustomerModel)Session[CUSTOMER]); return RedirectToAction("editAccountView"); } _loggingBLL.logToUser("Oppdaterte bruker: " + userModel.username + " (BrukerID: " + userModel.ID + ")", (CustomerModel)Session[CUSTOMER]); _loggingBLL.logToDatabase("Bruker: " + userModel.username + " (BrukerID: " + userModel.ID + ") ble oppdatert."); return RedirectToAction("accountView"); }
public List<OrderModel> findOrders(CustomerModel customerModel) { var orderModelList = new List<OrderModel>(); using(var db = new CustomerContext()) { try { var orders = (from o in db.Orders where o.personID == customerModel.customerID || o.Customers.email.Equals(customerModel.email) || o.Customers.phone.Equals(customerModel.phone) select o).OrderBy(o => o.orderNr).ToList(); foreach (var o in orders) orderModelList.Add(createOrderModel(o)); return orderModelList; } catch (Exception ex) { _logging.logToDatabase(ex); } return null; } }
public override bool logToUser(string message, CustomerModel model) { if (message == "") return false; return true; }
public abstract bool logToUser(string message, CustomerModel model);
public bool add(CustomerModel IncCustomer) { if (IncCustomer.firstName != "") return true; return false; }
//Oppdaterer customeren som har customerID lik customerModel.customerID public bool update(CustomerModel customerModel) { using (var db = new CustomerContext()) { try { var customer = (from c in db.Customers where c.personID == customerModel.customerID select c).FirstOrDefault(); if (customer == null)//tester om customeren finnes return false; //Persondataendring: customer.email = customerModel.email; customer.firstName = customerModel.firstName; customer.lastName = customerModel.lastName; customer.phone = customerModel.phone; customer.users.username = customerModel.email; db.SaveChanges(); //Adresseendring: var adressModel = new AdressModel(); adressModel.personID = customerModel.customerID; adressModel.deliveryAdress = true; adressModel.payAdress = customerModel.sameAdresses; adressModel.province = customerModel.province; adressModel.streetName = customerModel.adress; adressModel.zipCode = customerModel.zipCode; addAdress(adressModel); if (!customerModel.sameAdresses) { adressModel = new AdressModel(); adressModel.personID = customerModel.customerID; adressModel.deliveryAdress = false; adressModel.payAdress = true; adressModel.province = customerModel.payProvince; adressModel.streetName = customerModel.payAdress; adressModel.zipCode = customerModel.payZipcode; addAdress(adressModel); } return true; }//emd try catch (Exception ex) { _logging.logToDatabase(ex); } }//end using return false; }
//Oppdaterer customeren som har customerID lik customerModel.customerID public bool update(CustomerModel customerModel) { return _customerDAL.update(customerModel); }
//Legger customer inn i datatbasen public bool add(CustomerModel IncCustomer) { return _customerDAL.add(IncCustomer); }
public override bool logToUser(string message, CustomerModel model) { createLog(LOG_INTERACTION); string logLine = ""; if(model == null) { string strHostName = System.Net.Dns.GetHostName(); IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(strHostName); string ipaddress = ipEntry.AddressList[2].ToString(); model = new CustomerModel() { customerID = 0, firstName = ipaddress, lastName = "", email = "Anonym" }; } logLine = ",{ " + "\"Date\": \"" + DateTime.Now.ToString("h:mm:ss tt") + "\"," + "\"UserID\": \"" + model.email + "\"," + "\"User\": \"" + model.firstName + " " + model.lastName + "\"," + "\"Action\": \"" + message + "\" }"; try { using (StreamWriter logWriter = File.AppendText(LOG_INTERACTION)) { logWriter.WriteLine(logLine); logWriter.Close(); return true; } } catch (Exception) { System.Console.WriteLine("ERROR: COULD NOT LOG ACTION TO USER."); } return false; }
public void EditTestPostTrue() { //Arrange var controller = MockHttpSession.getMoqAdminCustomerController(); var customerModel = new CustomerModel(); customerModel.customerID = 1; customerModel.firstName = "Ola"; customerModel.lastName = "Nordmann"; customerModel.payAdress = "Osloveien 1"; customerModel.payProvince = "Oslo"; customerModel.payZipcode = "1234"; customerModel.phone = "12345678"; customerModel.province = "Oslo"; customerModel.sameAdresses = true; customerModel.zipCode = "1234"; customerModel.adress = "Osloveien 1"; //Act controller.Session["Employee"] = new EmployeeModel(); controller.Session["tempCID"] = 1; var result = (RedirectToRouteResult)controller.Edit(customerModel); //Assert Assert.AreEqual(result.RouteName, ""); Assert.AreEqual(result.RouteValues.Values.First(), "AllCustomers"); }
//Henter ut en CustomerModel for customer med customerID lik id public CustomerModel find(int id) { var customerModel = new CustomerModel(); using (var db = new CustomerContext()) { try { var temp = (from c in db.Customers where c.personID == id select c).FirstOrDefault(); if (temp == null)//Tester om customeren finnes return null; customerModel.customerID = temp.personID; customerModel.firstName = temp.firstName; customerModel.lastName = temp.lastName; customerModel.email = temp.email; customerModel.phone = temp.phone; List<Adresses> adresses = (from a in db.Adresses where a.personID == customerModel.customerID select a).ToList(); foreach (var a in adresses)//Legger adressene inn i CustomerModelen { if (a.deliveryAdress) { customerModel.adress = a.streetName; customerModel.province = a.province.province; customerModel.zipCode = a.zipCode; } if (a.payAdress) { customerModel.payAdress = a.streetName; customerModel.payProvince = a.province.province; customerModel.payZipcode = a.zipCode; } } return customerModel; }//end try catch (Exception ex) { _logging.logToDatabase(ex); } }//end using return null; }
public bool update(CustomerModel customerModel) { if (customerModel.firstName != "") return true; return false; }
//Legger customer inn i datatbasen public bool add(CustomerModel IncCustomer) { using (var db = new CustomerContext()) { try { if (!(db.Customers.Find(IncCustomer.customerID) == null))//Hvis IncCustomer har customerID som finnes fra før return false; if (find(IncCustomer.email) != null)//Tester om eposten er i bruk fra før return false; var newCustomer = new Customers()//Opretter ny customer { email = IncCustomer.email, firstName = IncCustomer.firstName, lastName = IncCustomer.lastName, phone = IncCustomer.phone }; newCustomer = db.Customers.Add(newCustomer); db.SaveChanges(); IncCustomer.customerID = newCustomer.personID;//Lagrer customerID i modellen for senere bruk } catch (Exception ex) { _logging.logToDatabase(ex); return false; } }//end using //Legger til adresser //Sjekker om adressene er like if (IncCustomer.payAdress.Equals(IncCustomer.adress)) { var adressModel = new AdressModel() { personID = IncCustomer.customerID, payAdress = true, deliveryAdress = true, zipCode = IncCustomer.zipCode, streetName = IncCustomer.adress, province = IncCustomer.province }; addAdress(adressModel); } //Ulike adresser else { var newPaymentAdress = new AdressModel() { personID = IncCustomer.customerID, payAdress = true, deliveryAdress = false, zipCode = IncCustomer.payZipcode, streetName = IncCustomer.payAdress, province = IncCustomer.payProvince }; addAdress(newPaymentAdress); var newAdress = new AdressModel() { personID = IncCustomer.customerID, payAdress = false, deliveryAdress = true, zipCode = IncCustomer.zipCode, streetName = IncCustomer.adress, province = IncCustomer.province }; addAdress(newAdress); } return true; }
public bool logToUser(string action, CustomerModel model) { return _loggingDAL.logToUser(action, model); }
public ActionResult Edit(CustomerModel customerModel) { customerModel.customerID = (int)Session["tempCID"]; if (_customerBLL.update(customerModel)) { _loggingBLL.logToUser("Oppdaterte bruker: " + customerModel.email + " (BrukerID: " + customerModel.customerID + ")", (EmployeeModel)Session["Employee"]); _loggingBLL.logToDatabase("Bruker oppdatert: " + customerModel.email + " (BrukerID: " + customerModel.customerID + ")"); return RedirectToAction("AllCustomers"); } else { return View(); } }
public List<OrderModel> findOrders(CustomerModel customerModel) { return _orderDAL.findOrders(customerModel); }
//Henter ut navn på bruker med brukernavn lik email public CustomerModel find(string email) { var customerModel = new CustomerModel(); using (var db = new CustomerContext()) { try { var temp = (from c in db.Customers where c.email == email select c).SingleOrDefault(); if (temp == null) //I prinsippet ikke nødvendig da denne metoden blir trigget da en kunde eksisterer return null; return find(temp.personID); } catch (Exception ex) { _logging.logToDatabase(ex); } return null; } }