Exemplo n.º 1
0
        public void ChangeListName(int listId, string newName)
        {
            var entity = new TodoList()
            {
                Id = listId,
            };

            _todoContext.Attach(entity);
            entity.Name = newName;

            _todoContext.SaveChanges();

            _pushService.SendListRenamed(listId, newName);
        }
Exemplo n.º 2
0
        public IActionResult UpdateStatusSet(long ssId, string statusSetJson)
        {
            StatusSet newStatusSet = StatusSetFromJson(statusSetJson);

            if (newStatusSet == null)
            {
                return(BadRequest());
            }
            using (var context = new TodoContext()) {
                StatusSet oldStatusSet = context.StatusSets.Find(ssId);
                if (oldStatusSet == null)
                {
                    return(NotFound());
                }
                var oldEnt = context.Attach(oldStatusSet);
                oldEnt.Collection("Statuses").Load();
                oldStatusSet.Name = newStatusSet.Name;
                foreach (var status in oldStatusSet.Statuses)
                {
                    var ent = context.Statuses.Remove(status);
                }
                oldStatusSet.Statuses.Clear();
                foreach (var status in newStatusSet.Statuses)
                {
                    context.Statuses.Add(status);
                    oldStatusSet.Statuses.Add(status);
                }
                context.SaveChanges();
                return(NoContent());
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Get a short representation of the status set.
 /// </summary>
 /// <param name="ss">The StatusSet to format</param>
 /// <returns>An anonymous object representing the StatusSet</returns>
 public object GetShortModel(StatusSet ss)
 {
     using (var context = new TodoContext()) {
         var entity = context.Attach(ss);
         entity.Collection("Statuses").Load();
         ss = entity.Entity;
     }
     return(ss);
 }
Exemplo n.º 4
0
 public IActionResult DeleteStatusSet(long ssId)
 {
     using (var context = new TodoContext()) {
         StatusSet oldStatusSet = context.StatusSets.Find(ssId);
         if (oldStatusSet == null)
         {
             return(NotFound());
         }
         var oldEnt = context.Attach(oldStatusSet);
         oldEnt.Collection("Statuses").Load();
         foreach (var status in oldStatusSet.Statuses)
         {
             context.Statuses.Remove(status);
         }
         context.StatusSets.Remove(oldStatusSet);
         context.SaveChanges();
         return(NoContent());
     }
 }
Exemplo n.º 5
0
 public Assignee Create(Assignee assignee)
 {
     _ctx.Attach(assignee).State = EntityState.Added;
     _ctx.SaveChanges();
     return(assignee);
 }
 public ActionResult Edit(Models.Todo todo)
 {
     todoContext.Attach(todo);
     todoContext.SaveChanges();
     return(RedirectToAction("Index"));
 }
Exemplo n.º 7
0
 public Task Create(Task task)
 {
     _ctx.Attach(task).State = EntityState.Added;
     _ctx.SaveChanges();
     return(task);
 }