Beispiel #1
0
        public void UpdateTask(TaskItem task)
        {
            try
            {
                UpadteTaskDependencies(task.DependentTasks, task.Id);

                var taskTosave = db.Tasks.Find(task.Id);

                //can use automapper
                taskTosave.DependentTasks = null;
                taskTosave.Description    = task.Description;
                taskTosave.Title          = task.Title;
                taskTosave.Complete       = task.Complete;

                db.Entry(taskTosave).State = System.Data.Entity.EntityState.Modified;
                if (db.SaveChanges() <= 0)
                {
                    throw new Exception("Update statement failed to change any records");
                }
            }
            catch (Exception ex)
            {
                throw new ServiceException("Task not updated", ex);
            }
        }
        public async Task <IActionResult> PutTask(int id, Entities.Task task)
        {
            if (id != task.Id)
            {
                return(BadRequest());
            }

            _context.Entry(task).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TaskExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #3
0
        public HttpResponseMessage UpdateTask(int id, Task t)
        {
            HttpResponseMessage res;

            try
            {
                if (t.TaskId == id)
                {
                    db.Entry(t).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                    res = new HttpResponseMessage(HttpStatusCode.OK);
                    return(res);
                }
                else
                {
                    res = new HttpResponseMessage(HttpStatusCode.NotModified);
                    return(res);
                }
            }
            catch
            {
                res = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                return(res);
            }
        }
Beispiel #4
0
        public async Task <T> UpdateAsync(T entity)
        {
            _dbContext.Entry(entity).State = EntityState.Modified;
            await _dbContext.SaveChangesAsync();

            return(entity);
        }
Beispiel #5
0
 public ActionResult Edit([Bind(Include = "Id,ScheduleDate,Description")] Schedule schedule)
 {
     if (ModelState.IsValid)
     {
         db.Entry(schedule).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(schedule));
 }
Beispiel #6
0
 public ActionResult Edit([Bind(Include = "ID,Title,Description,ExecutionDate")] Task task)
 {
     if (ModelState.IsValid)
     {
         db.Entry(task).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("List"));
     }
     return(View(task));
 }
Beispiel #7
0
        public async Task <IHttpActionResult> UpdateTasks(int id, [FromBody] UpdateTask updateTask)
        {
            var task = await _dbContext.Tasks.FindAsync(id);

            _dbContext.Entry(task).CurrentValues.SetValues(updateTask);

            await _dbContext.SaveChangesAsync();

            return(Ok());
        }
Beispiel #8
0
 public ActionResult Edit([Bind(Include = "Id,FullName,Email,Phone")] User user)
 {
     if (ModelState.IsValid)
     {
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Beispiel #9
0
 public ActionResult Edit([Bind(Include = "Id,Title,Description,StartDate,EndDate,Status")] Task task)
 {
     if (ModelState.IsValid)
     {
         db.Entry(task).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(task));
 }
 public IActionResult PostEvent([FromForm] EventList _event)
 {
     using (_context)
     {
         var addedEntity = _context.Entry(_event);
         addedEntity.State = (Microsoft.EntityFrameworkCore.EntityState)EntityState.Added;
         _context.SaveChanges();
     }
     return(Ok());
 }
        public IActionResult UpdateTask(Tasks newTasks)
        {
            newTasks.UserId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (ModelState.IsValid)
            {
                Tasks oldTasks = _context.Tasks.Find(newTasks.Id);
                oldTasks.TaskName    = newTasks.TaskName;
                oldTasks.Description = newTasks.Description;
                oldTasks.DueDate     = newTasks.DueDate;
                oldTasks.Complete    = newTasks.Complete;
                oldTasks.Id          = newTasks.Id;


                _context.Entry(oldTasks).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                _context.Tasks.Update(oldTasks);
                _context.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
        // This method should be used to update task details into database
        public async Task <int> UpdateTask(UserTask task)
        {
            if (context != null)
            {
                context.Entry(task).State = EntityState.Modified;
                await context.SaveChangesAsync();

                return(task.TaskId);
            }
            return(0);
        }
        public ActionResult Edit(Task task)
        {
            using (var db = new TaskDbContext())
            {
                if (ModelState.IsValid)
                {
                    db.Entry(task).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return(RedirectToAction("Index", "Home"));
            }
        }
        public IHttpActionResult PutTask(int id, Task task)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != task.Id)
            {
                return(BadRequest());
            }

            db.Entry(task).State = EntityState.Modified;
            task.UpdatedAt       = DateTime.Now;

            Task oldTask = db.Tasks.Find(id);

            // save deleted date
            if (!oldTask.Deleted && task.Deleted)
            {
                task.DeletedAt = DateTime.Now;
            }
            // save completed at
            if (!oldTask.Completed && task.Completed)
            {
                task.CompletedAt = DateTime.Now;
            }
            if (oldTask.Completed && !task.Completed)
            {
                task.CompletedAt = null;
            }

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TaskExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public TaskEntity UpdateTask(TaskEntity task)
        {
            var returnedTask = FindTaskById(task.Id);

            if (IsTaskNull(returnedTask))
            {
                throw new System.Data.Entity.Core.
                      ObjectNotFoundException("The task not found.");
            }

            _taskDbContext.Entry(returnedTask).CurrentValues.SetValues(task);

            Save();
            return(returnedTask);
        }
Beispiel #16
0
        public void UpdateTask(TaskItem task)
        {
            try
            {
                db.Entry(task).State = System.Data.Entity.EntityState.Modified;

                if (db.SaveChanges() <= 0)
                {
                    throw new Exception("Update statement failed to change any records");
                }
            }
            catch (Exception ex)
            {
                throw new ServiceException("Task not updated", ex);
            }
        }
Beispiel #17
0
        public IActionResult UpdateTask(Tasks newTask)
        {
            if (ModelState.IsValid)
            {
                //locate the task that the user wants to update
                Tasks oldTask = _context.Tasks.Find(newTask.Id);

                //set the old task to new task attributes
                oldTask.TaskDescription = newTask.TaskDescription;
                oldTask.DueDate         = newTask.DueDate;
                oldTask.Completed       = newTask.Completed;

                _context.Entry(oldTask).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                _context.Update(oldTask);
                _context.SaveChanges();
                return(RedirectToAction("ListTask"));
            }
            return(View());
        }
Beispiel #18
0
 public void ModifyTask(Task task)
 {
     taskDbContext.Entry(task).State = EntityState.Modified;
     taskDbContext.SaveChanges();
 }
Beispiel #19
0
 public void Update(Board updatedBoard)
 {
     _context.Entry(updatedBoard).State = EntityState.Modified;
     _context.SaveChanges();
 }
Beispiel #20
0
 public virtual void Update(T entity)
 {
     dbSet.Attach(entity);
     dataContext.Entry(entity).State = EntityState.Modified;
 }