public bool AddPerson(Person person, Role role, string password)
        {
            if (person.Email == "")
                return false;

            return true;
        }
Exemplo n.º 2
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;
                    }
                }
            }
        }
 public bool UpdatePerson(Person personUpdate, string email)
 {
     return AccountRepository.UpdatePerson(personUpdate, email);
 }
 public bool AddPerson(Person person, Role role, string password)
 {
     return AccountRepository.AddPerson(person, role, password);
 }
        public ActionResult UpdatePersonData(CustomerView customerEdit, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var email = customerEdit.Email;

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

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

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

            return _accountBLL.UpdatePerson(personUpdate, email);
        }
        public bool Register(CustomerRegisterPartial customer, string returnUrl)
        {
            var person = new Person()
            {
                Email = customer.Email,
                Firstname = customer.Firstname,
                Lastname = customer.Lastname,
                Address = customer.Address,
                Postal = new Postal
                {
                    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;
        }
 public bool UpdatePerson(Person personUpdate, string email)
 {
     throw new NotImplementedException();
 }
        public bool UpdatePerson(Person personUpdate, int personId)
        {
            if (personId == 0)
                return false;

            return true;
        }
 public Person GetPerson(string email)
 {
     if (email == "")
     {
         var person = new Person()
         {
             Email=""
         };
         return person;
     }
     else
     {
         var person = new Person()
         {
             Email = "*****@*****.**",
             Firstname = "Ole",
             Lastname = "Olsen",
             Address = "Persveien 5",
             Postal = new Postal
             {
                 Zipcode = "1234",
                 City = "Test"
             }
         };
         return person;
     }
 }
        public List<Person> GetAllPeople()
        {
            var list = new List<Person>();
            var person = new Person()
            {
                Email = "*****@*****.**",
                Firstname = "Ole",
                Lastname = "Olsen",
                Address = "Persveien 5",
                Postal = new Postal
                {
                    Zipcode = "1234",
                    City = "Test"
                }
            };

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

            return list;
        }
 public bool UpdatePerson(Person personUpdate, string email)
 {
     return _accountrepo.UpdatePerson(personUpdate, email);
 }