public bool UpdateScheduledTask(int id, CustomerScheduledTaskDto taskModel) { // get the curent scheduled task var existingTask = _context.customerscheduledtasks.FirstOrDefault(x => x.Id == id); // unbox to the correct object for scheduled task var updatedTask = Mapper.Map <customerscheduledtask>(taskModel); updatedTask.StartTime = taskModel.StartTimeDate.TimeOfDay; updatedTask.ModifiedBy = taskModel.ModifiedBy; updatedTask.Modified = DateTime.UtcNow; _context.Entry(existingTask).CurrentValues.SetValues(updatedTask); _context.SaveChanges(); return(true); }
public JsonResult _SaveScheduledTask(string taskType) { var taskModel = new CustomerScheduledTaskDto(); // update the model TryUpdateModel((dynamic)taskModel); taskModel.ModifiedBy = User.Identity.Name; if (taskModel.Id == -1) { _customerScheduledTaskService.CreateScheduledTask(taskModel); } else { _customerScheduledTaskService.UpdateScheduledTask(taskModel.Id, taskModel); } return(Json(taskModel, JsonRequestBehavior.AllowGet)); }
public bool CreateScheduledTask(CustomerScheduledTaskDto taskModel) { try { // unbox the correct object type for the credential var task = Mapper.Map <customerscheduledtask>(taskModel); task.StartTime = taskModel.StartTimeDate.TimeOfDay; task.CreatedBy = taskModel.ModifiedBy; task.Created = DateTime.UtcNow; _context.customerscheduledtasks.Add(task); _context.SaveChanges(); taskModel.Id = task.Id; } catch (DbEntityValidationException ex) { var errorMsg = EisHelper.ParseDbEntityValidationException(ex); return(false); } return(true); }