public void InsertOrUpdate(ScheduleItem scheduleitem)
 {
     if (scheduleitem.ID == default(int))
     {
         // New entity
         this.context.ScheduleItems.Add(scheduleitem);
     }
     else
     {
         // Existing entity
         this.context.Entry(scheduleitem).State = EntityState.Modified;
     }
 }
        public ActionResult AssignSchedule(int serviceTicketId, int employeeId, float startTime)
        {
            this.scheduleItemRepository.All.Where(e => e.ServiceTicketID == serviceTicketId)
                                          .ToList()
                                          .ForEach(e => this.scheduleItemRepository.Delete(e.ID));

            var serviceTicket = this.serviceTicketRepository.Find(serviceTicketId);
            var time = string.Format("Mon 16 May {0:d2}:{1:d2} {2} 2011", ((int)startTime > 12 ? (int)startTime - 12 : (int)startTime) / 1, startTime % 1 == 0.5 ? 30 : 0, startTime < 12 ? "AM" : "PM");
            var startAt = DateTime.ParseExact(time, "ddd dd MMM h:mm tt yyyy", System.Globalization.CultureInfo.InvariantCulture);
            var scheduleItem = new ScheduleItem { EmployeeID = employeeId, ServiceTicketID = serviceTicketId, Start = startAt, WorkHours = 1, AssignedOn = DateTime.Now };
            this.scheduleItemRepository.InsertOrUpdate(scheduleItem);
            serviceTicket.AssignedToID = employeeId;

            this.serviceTicketRepository.Save();
            this.scheduleItemRepository.Save();

            return RedirectToAction("Index", new { serviceTicket.ID });
        }