public IActionResult Create(int id) { var model = new ListToDoCreate(); model.DirectoryId = id; return(View(model)); }
public IActionResult Create(ListToDoCreate model) { if (ModelState.IsValid) { toDoService.Create(model, User.Identity.Name); return(Redirect(Constants.ReactAppPath + "/" + model.DirectoryId)); } return(Redirect("/Directory/IndexReact/" + model.DirectoryId)); }
//Authenticated //Registers user for the list public void Create(ListToDoCreate pageListToDo, string username) { var user = context.Users.SingleOrDefault(x => x.UserName == username); if (user == null) { throw new UserNotFound(username); } var direcotory = context.Directories.SingleOrDefault(x => x.Id == pageListToDo.DirectoryId); if (direcotory == null) { throw new ItemNotFound("The directory for this List does not exists"); } if (direcotory.UserId != user.Id) { throw new AccessDenied("The directory you are trying to create you List does not belong to you!"); } var order = 0; var ids = direcotory.ListsToDo.Select(x => x.Order).ToArray(); if (ids.Length != 0) { order = ids.Max() + 1; } var newListToDo = Mapper.Instance.Map <ListToDo>(pageListToDo); newListToDo.Order = order; newListToDo.Id = default(int); newListToDo.UserId = user.Id; context.ListsTodo.Add(newListToDo); context.SaveChanges(); }