public int AddTask(Task item) { int result = -1; tb.Tasks.Add(item); result = tb.SaveChanges(); return(result); }
public ActionResult Create([Bind(Include = "TaskListID,TaskListName")] TaskList taskList) { if (ModelState.IsValid) { db.TaskLists.Add(taskList); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(taskList)); }
public ActionResult Create([Bind(Include = "TaskID,TaskListID,TaskName,StartDate,EndDate,Completed")] Task task) { if (ModelState.IsValid) { db.Tasks.Add(task); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.TaskListID = new SelectList(db.TaskLists, "TaskListID", "TaskListName", task.TaskListID); return(View(task)); }
public ActionResult Create([Bind(Include = "UserID,FirstName,LastName,Telephone")] User user) { if (ModelState.IsValid) { user.UserID = Guid.NewGuid(); db.Users.Add(user); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(user)); }
public ActionResult Create([Bind(Include = "ProjectID,ProjectName,ProjectDescription,DateCreated")] Project project) { if (ModelState.IsValid) { project.ProjectID = Guid.NewGuid(); db.Projects.Add(project); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(project)); }
public ActionResult Create([Bind(Include = "StatusID,StatusText")] Status status) { if (ModelState.IsValid) { status.StatusID = Guid.NewGuid(); db.Statuses.Add(status); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(status)); }
public ActionResult Create([Bind(Include = "PriorityID,PriorityText")] Priority priority) { if (ModelState.IsValid) { priority.PriorityID = Guid.NewGuid(); db.Priorities.Add(priority); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(priority)); }
//[Route("DeleteTaskDetails")] public HttpResponseMessage Delete(int id) { try { using (TaskDBEntities entities = new TaskDBEntities()) { var entity = entities.tblTask.FirstOrDefault(t => t.QuoteID == id); if (entity == null) { //return 404 not found return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Task with ID=" + id.ToString() + " is not found to delete.")); } else { //delete the item entities.tblTask.Remove(entity); entities.SaveChanges(); //return 200 OK return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
//[Route("UpdateTaskDetails")] public HttpResponseMessage Put(int id, [FromBody] tblTask newTask) { try { using (TaskDBEntities entities = new TaskDBEntities()) { var entity = entities.tblTask.FirstOrDefault(t => t.QuoteID == id); if (entity == null) { //return 404 not found return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Task with ID=" + id.ToString() + " is not found to update.")); } else { entity.QuoteType = newTask.QuoteType; entity.ContactID = newTask.ContactID; entity.TaskDescription = newTask.TaskDescription; entity.TaskDueDate = newTask.TaskDueDate; entity.TaskType = newTask.TaskType; entities.SaveChanges(); //return 200 OK return(Request.CreateResponse(HttpStatusCode.OK, entity)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public IHttpActionResult PuttblUser(int id, tblUser tblUser) { using (TaskDBEntities entities = new TaskDBEntities()) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != tblUser.UserID) { return(BadRequest()); } entities.Entry(tblUser).State = EntityState.Modified; try { entities.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!tblUserExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); } }
public ActionResult Create([Bind(Include = "TaskID,ProjectID,UserID,PriorityID,StatusID,TaskDescription,DateCreated,DateEnd")] Task task) { if (ModelState.IsValid) { task.TaskID = Guid.NewGuid(); db.Tasks.Add(task); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.PriorityID = new SelectList(db.Priorities, "PriorityID", "PriorityText", task.PriorityID); ViewBag.ProjectID = new SelectList(db.Projects, "ProjectID", "ProjectName", task.ProjectID); ViewBag.StatusID = new SelectList(db.Statuses, "StatusID", "StatusText", task.StatusID); ViewBag.UserID = new SelectList(db.Users, "UserID", "FirstName", task.UserID); return(View(task)); }
public void DeleteTask(int id) { TaskDBEntities taskDBEntities = new TaskDBEntities(); TaskDetails task = taskDBEntities.TaskDetails.SingleOrDefault(p => p.Task_ID == id); var entry = taskDBEntities.Entry(task); if (entry.State == System.Data.Entity.EntityState.Detached) { taskDBEntities.TaskDetails.Attach(task); } taskDBEntities.TaskDetails.Remove(task); taskDBEntities.SaveChanges(); }
public void AddTask(TaskViewModel taskVM) { TaskDBEntities taskDBEntities = new TaskDBEntities(); TaskDetails task = new TaskDetails(); task.Task_Description = taskVM.TaskName; if (taskVM.ParentTaskName != null) { task.Parent_ID = taskDBEntities.TaskDetails.SingleOrDefault(p => p.Task_Description == taskVM.ParentTaskName).Task_ID; } task.Start_Date = Convert.ToDateTime(taskVM.Start_Date); task.End_Date = Convert.ToDateTime(taskVM.End_Date); task.Priority = taskVM.Priority; taskDBEntities.TaskDetails.Add(task); taskDBEntities.SaveChanges(); }
public void EditTask(TaskViewModel taskVM) { TaskDBEntities taskDBEntities = new TaskDBEntities(); TaskDetails task = taskDBEntities.TaskDetails.SingleOrDefault(p => p.Task_ID == taskVM.TaskID); if (taskVM.ParentTaskName != null && taskVM.ParentTaskName != "") { task.Parent_ID = taskDBEntities.TaskDetails.SingleOrDefault(p => p.Task_Description == taskVM.ParentTaskName).Task_ID; } task.Start_Date = Convert.ToDateTime(taskVM.Start_Date); task.End_Date = Convert.ToDateTime(taskVM.End_Date); task.Priority = taskVM.Priority; taskDBEntities.TaskDetails.Attach(task); taskDBEntities.Entry(task).State = System.Data.Entity.EntityState.Modified; taskDBEntities.SaveChanges(); }
public HttpResponseMessage AddTask([FromBody] Task task) { try { using (TaskDBEntities entities = new TaskDBEntities()) { Task newTask = entities.Tasks.Add(task); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, newTask); message.Headers.Location = new Uri(Request.RequestUri + newTask.ID.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage UpdateTask(int id, [FromBody] Task task) { try { using (TaskDBEntities entities = new TaskDBEntities()) { var tsk = entities.Tasks.FirstOrDefault(t => t.ID == id); if (tsk == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Task with Id = " + id.ToString() + " not found")); } if (task.Data != null) { tsk.Data = task.Data; } if (task.Category != null) { tsk.Category = task.Category; } if (task.Status != null) { tsk.Status = task.Status; } if (task.TaskOrder != null) { tsk.TaskOrder = task.TaskOrder; } if (task.Priority != null) { tsk.Priority = task.Priority; } entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, tsk)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Post([FromBody] tblTask newTask) { try { using (TaskDBEntities entities = new TaskDBEntities()) { entities.tblTask.Add(newTask); entities.SaveChanges(); //show http status code response: 201 created var message = Request.CreateResponse(HttpStatusCode.Created, newTask); //create an instance of Uri of the newly created item message.Headers.Location = new Uri(Request.RequestUri + newTask.QuoteID.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage DeleteTask(int id) { try { using (TaskDBEntities entities = new TaskDBEntities()) { Task tsk = entities.Tasks.FirstOrDefault(t => t.ID == id); if (tsk == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Task with Id = " + id.ToString() + " not found")); } else { entities.Tasks.Remove(tsk); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public void Insert(TEntity entity) { dbSet.Add(entity); context.SaveChanges(); }
//public GenericRepository<Quote> QuoteRepository //{ // get // { // if (this.quoteRepository == null) // { // this.quoteRepository = new GenericRepository<Quote>(context); // } // return quoteRepository; // } //} public void Save() { context.SaveChanges(); }
public void UpdateAddedTasks(string addedTasks) { if (addedTasks == null) { Response.Write("Unable to add task into Tasks Table"); return; } TaskDBEntities taskDB = new TaskDBEntities(); JavaScriptSerializer taskListSerilizer = new JavaScriptSerializer(); Task task = (Task)taskListSerilizer.Deserialize(addedTasks, typeof(Task)); taskDB.Tasks.Add(task); taskDB.SaveChanges(); Response.Write("Task updated success"); }