public Admin GetAdmin(int adminId)
 {
     if (adminId == 0)
     {
         var admin = new Admin()
         {
             Email=""
         };
         return admin;
     }
     else
     {
         var admin = new Admin()
         {
             Email = "*****@*****.**",
             Firstname = "Ole",
             Lastname = "Olsen",
             Address = "Persveien 5",
             Postal = new Postal
             {
                 Zipcode = "1234",
                 City = "Test"
             },
             AdminId = 1
         };
         return admin;
     }
 }
Exemplo n.º 2
0
 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;
         }
     }
 }
Exemplo n.º 3
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 AddOldImage(int productId, string imageUrl, Admin changer)
 {
     return productId != -1;
 }