/// <summary> /// Updates to do list. /// </summary> /// <param name="todolist">The todolist.</param> /// <returns></returns> public ToDoListDTO UpdateToDoList(ToDoListDTO todolist) { ToDoListEntity entity = _mapper.Map <ToDoListDTO, ToDoListEntity>(todolist); _repo.Update(entity, todolist.Id); return(todolist); }
public ToDoListDTO UpdateToDoList(Guid id, ToDoListDTO toDoListDTO, string email) { _logger.LogInformation("ToDoListService -> Executing UpdateToDoList()"); //if the user didn't specify the date for the reminder if (toDoListDTO.EndDate == null) { toDoListDTO.IsReminded = false; //the list is not a reminded list } else { toDoListDTO.IsReminded = true; } ToDoList listToUpdate = _context .ToDoLists .Include(todo => todo.Items) .SingleOrDefault(todo => todo.Id.Equals(id) && todo.Owner.Equals(email)); if (listToUpdate == null) { throw new EntityNotFoundException(); } listToUpdate.UpdateData(toDoListDTO.CreateEntity(email)); _context.SaveChanges(); return(new ToDoListDTO(listToUpdate)); //return an updated dto }
public ActionResult <ToDoListDTO> Replace(int id, ToDoListDTO toDoListDTO) { toDoListDTO.Id = id; var toDoList = mapper.Map <ToDoList>(toDoListDTO); try { context.ToDoLists.Update(toDoList); context.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (context.ToDoLists.Find(id) == null) { return(NotFound()); } else { throw; } } toDoListDTO = mapper.Map <ToDoListDTO>(toDoList); return(toDoListDTO); }
public ToDoListDTO CreateToDoList(ToDoListDTO toDoListDTO, string email) { _logger.LogInformation("ToDoListService -> Executing CreateToDoList()"); //if the user didn't specify the date for the reminder if (toDoListDTO.EndDate == null) { toDoListDTO.IsReminded = false; //the list is not a reminded list } else { toDoListDTO.IsReminded = true; } ToDoList newList = toDoListDTO.CreateEntity(email); //new todo list position is 'highest' in the hierarchy for the specified user newList.Position = _context.ToDoLists .Where(x => x.Owner.Equals(email)) .Count(); _context.ToDoLists.Add(newList); _context.SaveChanges(); toDoListDTO.Id = newList.Id; toDoListDTO.Position = newList.Position; return(toDoListDTO); }
/// <summary> /// Gets the by identifier. /// </summary> /// <param name="id">The identifier.</param> /// <returns></returns> public ToDoListDTO GetById(long id) { var entity = _repo.GetWithCondition <ToDoListEntity>(x => x.Id == id).FirstOrDefault(); ToDoListDTO dto = _mapper.Map <ToDoListEntity, ToDoListDTO>(entity); return(dto); }
/// <summary> /// Adds to do list. /// </summary> /// <param name="todolist">The todolist.</param> /// <returns></returns> public ToDoListDTO AddToDoList(ToDoListDTO todolist) { ToDoListEntity entity = _mapper.Map <ToDoListDTO, ToDoListEntity>(todolist); entity.CreatedDate = DateTime.Now; _repo.Add(entity); return(todolist); }
public ActionResult <ToDoListDTO> AddToDoList(ToDoListDTO todolist) { _logger.Info(() => "Api AddProduct"); todolist.CreatedBy = (long)HttpContext.Request.HttpContext.Items["Userid"]; todolist.UpdatedBy = (long)HttpContext.Request.HttpContext.Items["Userid"]; _toDoListService.AddToDoList(todolist); return(StatusCode((int)HttpStatusCode.OK, todolist)); }
public ActionResult CreateToDoList([FromBody] ToDoListDTO list) { _logger.LogInformation("ToDoList.CreateToDoList() executed!"); if (!ModelState.IsValid) { return(BadRequest()); } return(CreatedAtAction(nameof(GetToDoList), new { id = list.Id }, new ToDoListDTO(_service.CreateToDoList(list, User.GetEmail())))); }
public void AddToDoList_InValidData() { ToDoListEntity entity = null; ToDoListDTO dto = null; _mapper.Setup(p => p.Map <ToDoListDTO, ToDoListEntity>(dto)).Returns(entity); _repo.Setup(p => p.Add(entity)).Returns(0); var returnObj = _toDoListService.AddToDoList(dto); Assert.IsTrue(returnObj == null); }
public ToDoList CreateToDoList(ToDoListDTO list, string owner) { ToDoList result = list.ToEntity(); result.Position = _context.ToDoLists.Where(l => l.Owner == owner).Count(); result.Reminded = true; result.Owner = owner; _context.ToDoLists.Add(result); _context.SaveChanges(); return(result); }
public void AddToDoItem_ValidData() { var dto = new ToDoListDTO { Id = 11, Description = "List_11", LabelId = 1, CreatedBy = 1, UpdatedBy = 1, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }; _todoListService.Setup(p => p.AddToDoList(dto)).Returns(dto); var returnObj = todoListController.AddToDoList(dto); var okResult = returnObj.Result as ObjectResult; var valueResult = okResult.Value as ToDoListDTO; Assert.AreEqual(11, valueResult.Id); }
public async Task <bool> Update(ToDoListDTO toDoListDTO) { var stringContent = new StringContent(JsonConvert.SerializeObject(toDoListDTO), Encoding.UTF8, "application/json"); var response = await _httpClient.PutAsync("todolist", stringContent); if (response.IsSuccessStatusCode) { return(true); } else { return(false); } }
public ActionResult <ToDoListDTO> Create(ToDoListDTO toDoListDTO) { if (toDoListDTO != null) { var toDoList = mapper.Map <ToDoList>(toDoListDTO); context.ToDoLists.Add(toDoList); context.SaveChanges(); toDoListDTO = mapper.Map <ToDoListDTO>(toDoList); return(toDoListDTO); } else { return(BadRequest()); } }
public async Task <ToDoListDTO> AddAsync(ToDoListDTO toDoListDTO) { var stringContent = new StringContent(JsonConvert.SerializeObject(toDoListDTO), Encoding.UTF8, "application/json"); var response = await _httpClient.PostAsync("todolist", stringContent); if (response.IsSuccessStatusCode) { toDoListDTO = JsonConvert.DeserializeObject <ToDoListDTO>(await response.Content.ReadAsStringAsync()); return(toDoListDTO); } else { return(null); } }
public IActionResult UpdateToDoList([FromRoute] Guid id, [FromBody] ToDoListDTO toDoListDTO) { ToDoListDTO updatedDTO; try { updatedDTO = _service.UpdateToDoList(id, toDoListDTO, User.GetEmail()); } catch (EntityNotFoundException) { return(NotFound()); } return(Ok(updatedDTO)); }
public void AddToDoList_ValidData() { var dto = new ToDoListDTO { Id = 11, Description = "Desc_11", LabelId = 1, CreatedBy = 1, UpdatedBy = 1, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }; var entity = new ToDoListEntity { Id = 11, Description = "Desc_11", LabelId = 1, CreatedBy = 1, UpdatedBy = 1, CreatedDate = DateTime.Now, UpdatedDate = DateTime.Now }; _mapper.Setup(p => p.Map <ToDoListDTO, ToDoListEntity>(dto)).Returns(entity); _repo.Setup(p => p.Add(entity)).Returns(1); var returnObj = _toDoListService.AddToDoList(dto); Assert.AreEqual(11, returnObj.Id); }
public void UpdateToDoList(ToDoListDTO list, string owner) { ToDoList oldList = GetToDoList(list.Id, owner); if (oldList == null) { throw new EntityNotFoundException(); } else if (oldList.Owner != owner) { throw new UnauthorizedException(); } oldList.Update(list.ToEntity()); _context.SaveChanges(); }
public async Task <IActionResult> UdateToDoList(long id, ToDoListDTO toDoListDTO) { ApplicationUser user = await GetUser(); if (user == null) { return(Unauthorized()); } var toDoList = user.ToDoLists.SingleOrDefault(t => t.Id == id); if (id != toDoList.Id) { return(BadRequest()); } if (toDoList == null) { return(NotFound()); } toDoList.Name = toDoListDTO.Name; _context.Entry(toDoList).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ToDoListExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult UpdateToDoList([FromBody] ToDoListDTO list) { _logger.LogInformation("ToDoList.UpdateToDoList() executed!"); if (!ModelState.IsValid) { return(BadRequest()); } try { _service.UpdateToDoList(list, User.GetEmail()); return(Ok()); } catch (EntityNotFoundException) { return(NotFound()); } catch (UnauthorizedException) { return(Unauthorized()); } }
public async Task <ActionResult <ToDoListDTO> > CeateToDoList(ToDoListDTO toDoListDTO) { ApplicationUser user = await GetUser(); if (user == null) { return(Unauthorized()); } var toDoList = new ToDoList { Name = toDoListDTO.Name, User = user, UserId = user.Id }; _context.ToDoLists.Add(toDoList); await _context.SaveChangesAsync(); return(CreatedAtAction( nameof(GetToDoList), new { id = toDoList.Id }, ListToDTO(toDoList))); }
public async Task <IActionResult> Update(ToDoListDTO toDoListDTO) { await _toDoListApiService.Update(toDoListDTO); return(RedirectToAction("Index")); }
public IActionResult CreateToDoList([FromBody] ToDoListDTO toDoListDTO) { ToDoListDTO newListDTO = _service.CreateToDoList(toDoListDTO, User.GetEmail()); return(CreatedAtAction(nameof(GetToDoList), new { id = newListDTO.Id }, newListDTO)); }
/// <summary> /// Adds to do list. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public ToDoListDTO AddToDoList(ToDoListDTO item) { return(_todoListService.AddToDoList(item)); }
/// <summary> /// Updates to do list. /// </summary> /// <param name="item">The item.</param> /// <returns></returns> public ToDoListDTO UpdateToDoList(ToDoListDTO item) { return(_todoListService.UpdateToDoList(item)); }
public ActionResult <ToDoListDTO> UpdateToDoList(ToDoListDTO todolist) { todolist.UpdatedBy = (long)HttpContext.Request.HttpContext.Items["Userid"]; _toDoListService.UpdateToDoList(todolist); return(StatusCode((int)HttpStatusCode.OK, todolist)); }
public async Task <IActionResult> Save(ToDoListDTO toDoListDTO) { var newToDoList = await _toDoListService.AddAsync(_mapper.Map <ToDoList>(toDoListDTO)); return(Created(string.Empty, _mapper.Map <ToDoList>(newToDoList))); }
public IActionResult Update(ToDoListDTO toDoListDTO) { var toDoList = _toDoListService.Update(_mapper.Map <ToDoList>(toDoListDTO)); return(NoContent()); }