private bool ValidateModel(ContactTaskViewModel appointment, ModelStateDictionary modelState)
        {
            if (appointment.Start > appointment.End)
            {
                modelState.AddModelError("errors", "End date must be greater or equal to Start date.");
                return(false);
            }

            return(true);
        }
 public virtual void Update(ContactTaskViewModel task, ModelStateDictionary modelState)
 {
     if (ValidateModel(task, modelState))
     {
         var entity = task.ToEntity();
         db.ContactTasks.Attach(entity);
         db.Entry(entity).State = EntityState.Modified;
         db.SaveChanges();
     }
 }
        //public virtual List<Resource> GetTaskTypeByClientID(string clientId)
        //{

        //    List<Resource> resource = (from cu in db.ContactTasks

        //                               where cu.ClientId == clientId
        //                               select new Resource
        //                               {
        //                                   Value = cu.TaskType,
        //                                   Name = cu.TaskType,
        //                                   Color = cu.TaskColor
        //                               }).Distinct().ToList<Resource>();

        //    return resource;

        //}

        public virtual void Insert(ContactTaskViewModel task, ModelStateDictionary modelState)
        {
            if (ValidateModel(task, modelState))
            {
                var entity = task.ToEntity();

                db.ContactTasks.Add(entity);
                db.SaveChanges();

                task.TaskID = entity.TaskId;
            }
        }
        public virtual void Delete(ContactTaskViewModel task, ModelStateDictionary modelState)
        {
            var entity = task.ToEntity();

            db.ContactTasks.Attach(entity);

            var recurrenceExceptions = db.ContactTasks.Where(t => t.TaskId == task.TaskID);

            foreach (var recurrenceException in recurrenceExceptions)
            {
                db.ContactTasks.Remove(recurrenceException);
            }

            db.ContactTasks.Remove(entity);
            db.SaveChanges();
        }