Exemplo n.º 1
0
        public void Edit(object oldCM, object newCM)
        {
            List <Backend.ClubMember> Allclubmems = itsDAL.ReadFromFile(Elements.ClubMember).Cast <Backend.ClubMember>().ToList();

            //Check for credit card conflict
            if (((Backend.ClubMember)newCM).CreditCard != null && !((Backend.ClubMember)newCM).CreditCard.Equals(((Backend.ClubMember)oldCM).CreditCard))
            {
                foreach (Backend.ClubMember clubmem in Allclubmems)
                {
                    if (clubmem.CreditCard != null && clubmem.CreditCard.CreditNumber == ((Backend.ClubMember)newCM).CreditCard.CreditNumber)
                    {
                        throw new System.Data.DataException("The Credit Card ID allready exist in the system");
                    }
                }
            }
            //preserve the id for the edited clubmember
            ((Backend.ClubMember)newCM).MemberID = ((Backend.ClubMember)oldCM).MemberID;
            List <Backend.User> oldUserList = itsDAL.UserPersonQuery(oldCM);

            Backend.User oldUser = oldUserList.ElementAtOrDefault(0);
            if (oldUser == null)
            {
                throw new NullReferenceException("The clubmember does not exist!");
            }
            User_BL itsUserBL = new User_BL(itsDAL);

            Backend.User newUser = new Backend.User(oldUser);
            newUser.Person = newCM;
            itsUserBL.Remove(oldUser, true);
            this.Remove(oldCM);
            this.Add(newCM);
            itsUserBL.Add(newUser);
        }
Exemplo n.º 2
0
        public void Edit(object oldE, object newE)
        {
            if (((Backend.Employee)oldE).Id == -1)
            {
                throw new UnauthorizedAccessException("can't edit default administrator");
            }
            List <Backend.User> oldUserList = itsDAL.UserPersonQuery(oldE);

            Backend.User oldUser = oldUserList.ElementAtOrDefault(0);
            if (oldUser == null)
            {
                throw new NullReferenceException("The employee does not exist!");
            }
            if (((Backend.Employee)oldE).Id != ((Backend.Employee)newE).Id)
            {
                List <Backend.Employee> Allemps = itsDAL.ReadFromFile(Elements.Employee).Cast <Backend.Employee>().ToList();
                foreach (Backend.Employee emp in Allemps)
                {
                    if (((Backend.Employee)oldE).Id == emp.SupervisiorID)
                    {
                        throw new Exception("Cant Change ID, this employee has worker under him!");
                    }
                }
            }
            if (((Backend.Employee)newE).SupervisiorID != 0)
            {
                ((Backend.Employee)newE).Rank = Rank.Worker;
            }
            Backend.User newUser = new Backend.User(oldUser);
            this.Remove(oldE, true);
            newUser.Person = this.Add(newE);
            itsUserBL.Add(newUser);
        }
Exemplo n.º 3
0
 //User
 public Backend.User UserConverterToBackend(User dataContextUser)
 {
     Backend.User currentUser = new Backend.User();
     currentUser.UserName = dataContextUser.UserName;
     currentUser.Password = dataContextUser.Password;
     if (dataContextUser.PersonAsClubMember != null)
     {
         IQueryable personQuery = from ClubMember person in db.ClubMembers
                                  where person.Id == dataContextUser.PersonID
                                  select person;
         currentUser.Person = ClubMemberConverterToBackend(personQuery.Cast <ClubMember>().ToList().ElementAt(0));
     }
     else if (dataContextUser.PersonAsCustomer != null)
     {
         IQueryable personQuery = from Customer person in db.Customers
                                  where person.Id == dataContextUser.PersonID
                                  select person;
         currentUser.Person = CustomerConverterToBackend(personQuery.Cast <Customer>().ToList().ElementAt(0));
     }
     else if (dataContextUser.PersonAsEmployee != null)
     {
         IQueryable personQuery = from Employee person in db.Employees
                                  where person.Id == dataContextUser.PersonID
                                  select person;
         currentUser.Person = EmployeeConverterToBackend(personQuery.Cast <Employee>().ToList().ElementAt(0));
     }
     return(currentUser);
 }
Exemplo n.º 4
0
 //adds a user to database
 public void Add(Backend.User user)
 {
     if (!exist(user))
     {
         itsDAL.Add(user);
     }
 }
Exemplo n.º 5
0
        //Method for User Only
        public Backend.User isItValidUser(Backend.User user)
        {
            Boolean             isThereAdmin = false;
            List <Backend.User> Allusers     = itsDAL.ReadFromFile(Elements.User).Cast <Backend.User>().ToList();

            foreach (Backend.User _user in Allusers)
            {
                if ((_user.Person is Backend.Employee) && ((Backend.Employee)(_user.Person)).Rank == Rank.Administrator)
                {
                    isThereAdmin = true;
                }
            }
            if (!isThereAdmin)
            {
                DEFAULT_ADMIN.Rank = Rank.Administrator;
                Backend.User admin = new Backend.User(DEFAULT_USER_NAME, DEFAULT_PASSWORD, DEFAULT_ADMIN);
                Allusers.Add(admin);
            }
            if (user.UserName == null || user.Password == null)
            {
                throw new System.Data.DataException("Bad Input!");
            }
            foreach (Backend.User _user in Allusers)
            {
                if (_user.UserName.Equals(user.UserName) && _user.Password.Equals(user.Password))
                {
                    return(_user);
                }
            }
            throw new System.Data.DataException("The user does not exist in the Database!");
        }
Exemplo n.º 6
0
 public void Add(Object us)
 {
     Backend.User user = (Backend.User)us;
     DB.Add(user);
     DAL.User toAdd = Change.UserBackendToDal(user);
     sqlDB.Users.InsertOnSubmit(toAdd);
     sqlDB.SubmitChanges();
 }
Exemplo n.º 7
0
 public static DAL.User UserBackendToDal(Backend.User u)
 {
     DAL.User ans = new DAL.User();
     ans.ID       = u.ID;
     ans.userName = u.userName;
     ans.password = u.password;
     return(ans);
 }
Exemplo n.º 8
0
        [Test] // #20
        public void t()
        {      //@ check delete user
            User_Data ud = new User_Data();

            Backend.User u = new Backend.User("a", "a", "112233");
            ud.Remove(u);
            Assert.IsTrue(!ud.Contains(u));
        }
Exemplo n.º 9
0
        [Test] // #18
        public void r()
        {      //@ check user creation
            User_Data ud = new User_Data();

            Backend.User u = new Backend.User("a", "a", "112233");
            ud.Add(u);
            Assert.IsTrue(ud.Contains(u));
        }
Exemplo n.º 10
0
 //removes a user
 public Boolean Remove(Backend.User user)
 {
     if (exist(user))
     {
         return(itsDAL.Remove(user));
     }
     return(false);
 }
Exemplo n.º 11
0
 public User_Data(List <Backend.User> UDB)
 {
     DB = UDB;
     Backend.User admin = new Backend.User("admin", "admin", "admin");
     if (!Contains(admin))
     {
         DB.Add(admin);
     }
     sqlDB = new EmartDataContext();
 }
Exemplo n.º 12
0
 public bool Contains(Backend.User user)
 {
     foreach (Backend.User u in DB)
     {
         if ((u.userName).CompareTo(user.userName) == 0 && (u.password).CompareTo((user.password)) == 0)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 13
0
        ///////////////////////////////////////////////// User CONVERTION
        public static List <Backend.User> UserDalToBackendList(List <DAL.User> SqlDB)
        {
            List <Backend.User> list = new List <Backend.User>();

            Backend.User temp;
            foreach (DAL.User u in SqlDB)
            {
                temp = new Backend.User(u.userName, u.password, u.ID);
                list.Add(temp);
            }
            return(list);
        }
Exemplo n.º 14
0
 public Boolean Remove(Object us)
 {
     Backend.User user = (Backend.User)us;
     foreach (Backend.User u in DB)
     {
         if ((u.userName).CompareTo((user.userName)) == 0 && (u.password).CompareTo((user.password)) == 0)
         {
             user = u;
         }
     }
     DB.Remove(user);
     foreach (DAL.User u in sqlDB.Users)
     {
         if ((u.userName).CompareTo((user.userName)) == 0 && (u.password).CompareTo((user.password)) == 0)
         {
             sqlDB.Users.DeleteOnSubmit(u);
             sqlDB.SubmitChanges();
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 15
0
        public User UserConverterToContext(Backend.User currentUser)
        {
            User dataContextUser = new User();

            dataContextUser.Password = currentUser.Password;
            dataContextUser.UserName = currentUser.UserName;
            if (currentUser.Person is Backend.ClubMember)
            {
                dataContextUser.PersonAsClubMember = ((Backend.ClubMember)currentUser.Person).Id;
                dataContextUser.PersonID           = ((Backend.ClubMember)currentUser.Person).Id;
            }
            else if (currentUser.Person is Backend.Customer)
            {
                dataContextUser.PersonAsCustomer = ((Backend.Customer)currentUser.Person).Id;
                dataContextUser.PersonID         = ((Backend.Customer)currentUser.Person).Id;
            }
            else if (currentUser.Person is Backend.Employee)
            {
                dataContextUser.PersonAsEmployee = ((Backend.Employee)currentUser.Person).Id;
                dataContextUser.PersonID         = ((Backend.Employee)currentUser.Person).Id;
            }
            return(dataContextUser);
        }
Exemplo n.º 16
0
        public Boolean Update(Backend.User toUpdate, String newPass)
        {
            Boolean ans1 = false;
            Boolean ans2 = false;

            foreach (Backend.User u in DB)
            {
                if (u.userName == toUpdate.userName && u.password == toUpdate.password)
                {
                    u.password = newPass;
                    ans1       = true;
                }
            }
            foreach (DAL.User u in sqlDB.Users)
            {
                if (u.userName == toUpdate.userName && u.password == toUpdate.password)
                {
                    u.password = newPass;
                    sqlDB.SubmitChanges();
                    ans2 = true;
                }
            }
            return(ans1 && ans2);
        }
Exemplo n.º 17
0
 //checks if user(password&username) exsists in the database
 public bool exist(Backend.User user)
 {
     return(itsDAL.Contains(user));
 }
Exemplo n.º 18
0
 public Boolean Update(string name, String currPass, String newPass)
 {
     Backend.User u = new Backend.User(name, currPass);
     return(itsDAL.Update(u, newPass));
 }
Exemplo n.º 19
0
        //Methods:
        public object Add(object e)
        {
            //Add the new employee to the system
            List <Backend.Employee>   Allemps    = itsDAL.ReadFromFile(Elements.Employee).Cast <Backend.Employee>().ToList();
            List <Backend.Department> Alldeparts = itsDAL.ReadFromFile(Elements.Department).Cast <Backend.Department>().ToList();
            bool checkID  = false;
            bool checkSup = false;

            //check id the employee's department accually exists
            foreach (Backend.Department dep in Alldeparts)
            {
                if (((Backend.Employee)e).DepID == dep.DepartmentID)
                {
                    checkID = true;
                    break;
                }
            }
            if (!checkID)
            {
                throw new Exception("department ID doesn't exist!");
            }
            else
            {
                foreach (Backend.Employee emp in Allemps)
                {
                    if (emp.Equals(e))
                    {
                        throw new Exception("employee is already exists!");
                    }
                    if (emp.Id == ((Backend.Employee)e).Id)
                    {
                        throw new Exception("This employee have duplicate ID with another employee!");
                    }
                    if (((Backend.Employee)e).SupervisiorID == emp.Id)
                    {
                        checkSup = true;
                        if ((emp.SupervisiorID != 0))
                        {
                            Backend.User oldUsr = itsDAL.UserPersonQuery(emp).ElementAt(0);
                            emp.Rank = Rank.Manager;
                            Backend.User newUser = new Backend.User(oldUsr);
                            newUser.Person = emp;
                            itsUserBL.Edit(oldUsr, newUser);
                        }
                    }
                    if (emp.SupervisiorID == ((Backend.Employee)e).Id)
                    {
                        Backend.User oldUsr = itsDAL.UserPersonQuery(((Backend.Employee)e)).ElementAtOrDefault(0);
                        if (oldUsr != null)
                        {
                            ((Backend.Employee)e).Rank = Rank.Manager;
                            Backend.User newUser = new Backend.User(oldUsr);
                            newUser.Person = ((Backend.Employee)e);
                            itsUserBL.Edit(oldUsr, newUser);
                        }
                    }
                }
                if (((Backend.Employee)e).SupervisiorID == 0)
                {
                    checkSup = true;
                    ((Backend.Employee)e).Rank = Rank.Administrator;
                }
                if (!checkSup)
                {
                    throw new Exception("his supervisor doesn't exists!");
                }
                Allemps.Add((Backend.Employee)e);
            }
            itsDAL.WriteToFile(Allemps.Cast <object>().ToList(), (Backend.Employee)e);
            return(e);
        }
Exemplo n.º 20
0
        public void Remove(object e, Boolean isEdit = false)
        {
            List <Backend.Employee> Allemps  = itsDAL.ReadFromFile(Elements.Employee).Cast <Backend.Employee>().ToList();
            List <Backend.User>     Allusers = itsDAL.ReadFromFile(Elements.User).Cast <Backend.User>().ToList();
            bool   hasMoreEmployees          = false;
            object temp = new Backend.Employee();

            Backend.User tempUser = new Backend.User();
            if (!Allemps.Any())
            {
                throw new NullReferenceException("No Employees to remove!");
            }
            if (!isEdit)
            {
                //check if this employee has workers under him
                foreach (Backend.Employee emp in Allemps)
                {
                    if (((Backend.Employee)e).Id == emp.SupervisiorID)
                    {
                        throw new Exception("this employee has worker under him!");
                    }
                }
            }
            foreach (Backend.User user in Allusers)
            {
                if (user.Person.Equals(e))
                {
                    Allusers.Remove(user);
                    break;
                }
            }
            foreach (Backend.Employee emp in Allemps)
            {
                if (emp.Equals(e))
                {
                    Allemps.Remove(emp);
                    break;
                }
            }
            foreach (Backend.Employee emp in Allemps)
            {
                if (((Backend.Employee)e).SupervisiorID == emp.SupervisiorID)
                {
                    hasMoreEmployees = true;
                }
                if (((Backend.Employee)e).SupervisiorID == emp.Id)
                {
                    temp     = emp;
                    tempUser = itsDAL.UserPersonQuery(temp).ElementAtOrDefault(0);
                }
            }
            if (!hasMoreEmployees && ((Backend.Employee)temp).SupervisiorID != 0 && ((Backend.Employee)temp).SupervisiorID != -1)
            {
                ((Backend.Employee)temp).Rank = Rank.Worker;
                Backend.User newUser = new Backend.User(tempUser);
                newUser.Person = temp;
                Allusers.Remove(tempUser);
                Allusers.Add(newUser);
            }

            itsDAL.WriteToFile(Allusers.Cast <object>().ToList(), new Backend.User());
            itsDAL.WriteToFile(Allemps.Cast <object>().ToList(), (Backend.Employee)e);
        }
Exemplo n.º 21
0
        public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl = null)
        {
            if (User.IsSignedIn())
            {
                return View();
                //return RedirectToAction(nameof(ManageController.Index), "Manage");
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await _signInManager.GetExternalLoginInfoAsync();
                if (info == null)
                {
                    return View("ExternalLoginFailure");
                }
                var user = new User { UserName = model.Email, Email = model.Email };
                var result = await _userManager.CreateAsync(user);
                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);
                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent: false);
                        //return RedirectToLocal(returnUrl);
                    }
                }
                AddErrors(result);
            }

            ViewData["ReturnUrl"] = returnUrl;
            return View(model);
        }