Exemplo n.º 1
0
        //as long as a single field below is unique, returns true
        public bool IsSalespersonUnique(Salesperson sp)
        {
            var isFirstNameUnique   = DBContext.Salespeople.Where(s => s.FirstName == sp.FirstName).Count() == 0;
            var isLastNameUnique    = DBContext.Salespeople.Where(s => s.LastName == sp.LastName).Count() == 0;
            var isAddressUnique     = DBContext.Salespeople.Where(s => s.Address == sp.Address).Count() == 0;
            var isPhoneNumberUnique = DBContext.Salespeople.Where(s => s.Phone == sp.Phone).Count() == 0;
            var isStartDateUnique   = DBContext.Salespeople.Where(s => s.StartDate == sp.StartDate).Count() == 0;

            if (isFirstNameUnique || isLastNameUnique || isAddressUnique || isPhoneNumberUnique || isStartDateUnique)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 2
0
 //allows addition or creation, but the app only supports updating at the moment
 public void AddOrUpateSalesperson(Salesperson sp)
 {
     if (DBContext.Salespeople.Select(x => x.SalespersonId).Contains(sp.SalespersonId))
     {
         var salesperson = (
             from s in DBContext.Salespeople
             where s.SalespersonId == sp.SalespersonId
             select s).SingleOrDefault();
         salesperson.FirstName       = sp.FirstName;
         salesperson.LastName        = sp.LastName;
         salesperson.Address         = sp.Address;
         salesperson.Phone           = sp.Phone;
         salesperson.StartDate       = sp.StartDate;
         salesperson.TerminationDate = sp.TerminationDate;
         salesperson.Manager         = sp.Manager;
     }
     else
     {
         DBContext.Salespeople.Add(sp);
     }
     DBContext.SaveChanges();
 }