public Appointment Update(Appointment t)
 {//TODO
     using (db = new HairstudioDBContext())
     {
         var ea = db.Appointments //ea = existing appointment
                  .Include(a => a.Hairdresser)
                  .Include(a => a.Customer)
                  .Include(a => a.TimeRange)
                  .FirstOrDefault(x => x.ID == t.ID);
         var hairdresser = db.Hairdressers.FirstOrDefault(x => x.ID == t.Hairdresser.ID);
         var customer    = db.Customers.FirstOrDefault(x => x.ID == t.Customer.ID);
         if (ea != null)
         {
             ea.Hairdresser         = hairdresser;
             ea.Customer            = customer;
             ea.TimeRange.TheDate   = t.TimeRange.TheDate;
             ea.TimeRange.EndTime   = t.TimeRange.EndTime;
             ea.TimeRange.StartTime = t.TimeRange.StartTime;
         }
         //var objectStateManager = ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager;
         //objectStateManager.ChangeObjectState(ea, EntityState.Modified);
         db.SaveChanges();
         return(t);
     }
 }
 public ServiceOffered Update(ServiceOffered t)
 {//TODO
     using (db = new HairstudioDBContext())
     {
         db.Entry(t).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(t);
     }
 }
 public bool Remove(ServiceOffered t)
 {
     using (db = new HairstudioDBContext())
     {
         db.Entry(t).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
         return(true);
     }
 }
 public ServiceOffered Create(ServiceOffered t)
 {
     using (db = new HairstudioDBContext())
     {
         db.ServicesOffered.Add(t);
         db.SaveChanges();
         return(t);
     }
 }
 public Customer Create(Customer t)
 {
     using (db = new HairstudioDBContext())
     {
         db.Customers.Add(t);
         db.SaveChanges();
         return(t);
     }
 }
 public Customer Update(Customer t)
 {
     using (db = new HairstudioDBContext())
     {
         db.Entry(t).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(t);
     }
 }
 public bool Remove(Customer t)
 {
     using (db = new HairstudioDBContext())
     {
         db.Entry(db.Customers.FirstOrDefault(x => x.ID == t.ID)).State = System.Data.Entity.EntityState.Deleted;
         db.SaveChanges();
         return(db.Customers.FirstOrDefault(x => x.ID == t.ID) == null);
     }
 }
 public TimeRange Update(TimeRange t)
 {//TODO
     using (db = new HairstudioDBContext())
     {
         db.Entry(t).State = System.Data.Entity.EntityState.Modified;
         db.SaveChanges();
         return(t);
     }
 }
 public TimeRange Create(TimeRange t)
 {
     using (db = new HairstudioDBContext())
     {
         db.TimeRanges.Add(t);
         db.SaveChanges();
         return(t);
     }
 }
 public Message Create(Message t)
 {
     using (db = new HairstudioDBContext())
     {
         db.Messages.Add(t);
         db.SaveChanges();
         return(t);
     }
 }
Exemple #11
0
 public Hairdresser Create(Hairdresser t)
 {
     using (db = new HairstudioDBContext())
     {
         db.Hairdressers.Add(t);
         db.SaveChanges();
         return(t);
     }
 }
 public Message Update(Message t)
 {//TODO
     using (db = new HairstudioDBContext())
     {
         var em = db.Messages.FirstOrDefault(x => x.ID == t.ID);
         if (em != null)
         {
             em.Description = t.Description;
             db.SaveChanges();
         }
         return(em);
     }
 }
 public Appointment Create(Appointment t)
 {
     using (db = new HairstudioDBContext())
     {
         var hairdresser = db.Hairdressers.FirstOrDefault(x => x.ID == t.Hairdresser.ID);
         var customer    = db.Customers.FirstOrDefault(x => x.ID == t.Customer.ID);
         t.Hairdresser = hairdresser;
         t.Customer    = customer;
         db.Appointments.Add(t);
         db.SaveChanges();
         return(t);
     }
 }
Exemple #14
0
        public Hairdresser Update(Hairdresser t)
        {//TODO
            using (db = new HairstudioDBContext())
            {
                var eh = db.Hairdressers
                         .Include(h => h.Appointments)
                         .Include(h => h.WorkingDays)
                         .FirstOrDefault(x => x.ID == t.ID);

                if (eh != null)
                {
                    //eh = Existing hairdresser
                    eh.Name         = t.Name;
                    eh.Email        = t.Email;
                    eh.Appointments = new List <Appointment>();
                    if (t.Appointments != null)
                    {
                        foreach (var a in t.Appointments)
                        {
                            eh.Appointments.Add(a);
                        }
                    }
                    eh.WorkingDays = new List <TimeRange>();
                    if (t.WorkingDays != null)
                    {
                        foreach (var w in t.WorkingDays)
                        {
                            eh.WorkingDays.Add(w);
                        }
                    }
                    //Password, usertype and ID are not to be changed here.
                    eh.PhoneNumber = t.PhoneNumber;
                    eh.Email       = t.Email;
                    eh.Username    = t.Username;
                    eh.Name        = t.Name;

                    if (t.Appointments != null)
                    {
                        foreach (var a in t.Appointments)
                        {
                            eh.Appointments.Add(db.Appointments.FirstOrDefault(x => x.ID == a.ID));
                        }
                    }
                }

                db.SaveChanges();

                return(eh);
            }
        }