Esempio n. 1
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);
        }
Esempio n. 2
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);
        }