Exemplo n.º 1
0
        public bool AddPerson(PersonModel person, Role role, string password)
        {
            if (person.Email == "")
                return false;

            return true;
        }
Exemplo n.º 2
0
 public bool UpdateCustomerInfo(CustomerView customerEdit)
 {
     if (Session["Email"] != null)
     {
         var email = customerEdit.Email;
         var personUpdate = new PersonModel()
         {
             Firstname = customerEdit.Firstname,
             Lastname = customerEdit.Lastname,
             Address = customerEdit.Address,
             Zipcode = customerEdit.Zipcode,
             City = customerEdit.City
         };
         if ((string)Session["Email"] == email || Session["Admin"] != null)
         {
             return _customerBLL.UpdatePerson(personUpdate, email);
         }
     }
     return false;
 }
Exemplo n.º 3
0
        public bool UpdatePerson(PersonModel personUpdate, string email)
        {
            // TODO: update admin/customer -id
            using (var db = new TankshopDbContext())
            {
                try
                {
                    var editPerson = db.People.Find(email);
                    var editPersonModel = GetPerson(email);

                    editPerson.Firstname = personUpdate.Firstname;
                    editPerson.Lastname = personUpdate.Lastname;
                    editPerson.Address = personUpdate.Address;

                    var personPostal = db.Postals.Find(personUpdate.Zipcode);
                    if (personPostal == null)
                    {
                        var oldPostal = db.Postals.Find(editPerson.Zipcode);
                        if (oldPostal != null)
                            oldPostal.People.Remove(editPerson);
                        db.SaveChanges();

                        personPostal = new Postal()
                        {
                            Zipcode = personUpdate.Zipcode,
                            City = personUpdate.City
                        };
                        personPostal.People.Add(editPerson);
                        db.SaveChanges();
                    }

                    editPerson.Zipcode = personUpdate.Zipcode;
                    editPerson.Postal = personPostal;

                    db.SaveChanges();

                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }
Exemplo n.º 4
0
        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;
                    }
                }
            }
        }
Exemplo n.º 5
0
        public bool UpdatePerson(PersonModel personUpdate, string email)
        {
            if (email == "")
                return false;

            return true;
        }
Exemplo n.º 6
0
        public bool UpdatePerson(PersonModel personUpdate, int personId)
        {
            if (personId == 0)
                return false;

            return true;
        }
Exemplo n.º 7
0
 public PersonModel GetPerson(string email)
 {
     if (email == "")
     {
         var person = new PersonModel()
         {
             Email=""
         };
         return person;
     }
     else
     {
         var person = new PersonModel()
         {
             Email = "*****@*****.**",
             Firstname = "Ole",
             Lastname = "Olsen",
             Address = "Persveien 5",
             Zipcode = "0123",
             City = "Oslo"
         };
         return person;
     }
 }
Exemplo n.º 8
0
 public bool UpdatePerson(PersonModel personUpdate, string email)
 {
     return _accountrepo.UpdatePerson(personUpdate, email);
 }
Exemplo n.º 9
0
        public List<PersonModel> GetAllPeople()
        {
            var list = new List<PersonModel>();
            var person = new PersonModel()
            {
                Email = "*****@*****.**",
                Firstname = "Ole",
                Lastname = "Olsen",
                Address = "Persveien 5",
                Zipcode = "0123",
                City = "Oslo"
            };

            list.Add(person);
            list.Add(person);
            list.Add(person);

            return list;
        }
Exemplo n.º 10
0
 public bool AddPerson(PersonModel person, Role role, string password)
 {
     return _repo.AddPerson(person, role, password);
 }
Exemplo n.º 11
0
        public ActionResult UpdatePersonData(CustomerView customerEdit, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var email = customerEdit.Email;

                var personUpdate = new PersonModel()
                {
                    Firstname = customerEdit.Firstname,
                    Lastname = customerEdit.Lastname,
                    Address = customerEdit.Address,
                    Zipcode = customerEdit.Zipcode,
                    City = customerEdit.City
                };

                if (_accountBLL.UpdatePerson(personUpdate, email))
                {
                    return RedirectToAction("MyPage");
                }
            }
            return Redirect(returnUrl);
        }
Exemplo n.º 12
0
        public bool UpdateCustomerInfo(CustomerView customerEdit, string returnUrl)
        {
            var email = (string)Session["Email"];

            var personUpdate = new PersonModel()
            {
                Firstname = customerEdit.Firstname,
                Lastname = customerEdit.Lastname,
                Address = customerEdit.Address,
                Zipcode = customerEdit.Zipcode,
                City = customerEdit.City
            };

            return _accountBLL.UpdatePerson(personUpdate, email);
        }
Exemplo n.º 13
0
        public bool Register(CustomerRegisterPartial customer, string returnUrl)
        {
            var person = new PersonModel()
            {
                Email = customer.Email,
                Firstname = customer.Firstname,
                Lastname = customer.Lastname,
                Address = customer.Address,
                Zipcode = customer.Zipcode,
                City = customer.City
            };

            if (_accountBLL.AddPerson(person, Role.Customer, customer.Password))
            {
                Session["LoggedIn"] = true;
                Session["Email"] = customer.Email;
                RedirectToAction("Index", "Home");
                return true;
            }
            return false;
        }
Exemplo n.º 14
0
        public bool UpdateCustomerInfo(CustomerView customerEdit)
        {
            var email = customerEdit.Email;

            var personUpdate = new PersonModel()
            {
                Firstname = customerEdit.Firstname,
                Lastname = customerEdit.Lastname,
                Address = customerEdit.Address,
                Zipcode = customerEdit.Zipcode,
                City = customerEdit.City
            };

            return _adminBLL.UpdatePerson(personUpdate, email);
        }