public async Task UpdateToDoListTest() { ToDoListDto result = await _toDoListContract.UpdateToDoList(new UpdateToDoListDto()); Assert.IsNotNull(result); Assert.AreEqual(1, result.ToDoListId); }
public async Task <ToDoListDto> GetByIdAsync(string userId, string listId) { if (!await this.IsUserOwnListAsync(userId, listId)) { throw new ArgumentException(GlobalConstants.NoPermissionForEditList); } var list = await this.dbContext.ToDoLists.Include(l => l.ListItems).FirstOrDefaultAsync(x => x.Id == listId); if (list == null) { throw new ArgumentException(GlobalConstants.ListNotExist); } var listDto = new ToDoListDto() { CreatedOn = list.CreatedOn, Id = list.Id, Name = list.Name, Status = list.Status, ListItems = list.ListItems.Select(x => new ToDoItemDto { Id = x.Id, Name = x.Name, Status = x.Status, CreatedOn = x.CreatedOn, }) .ToList(), }; return(listDto); }
public async Task AddToDoList() { ToDoListDto addedtoDoList = await _toDoListRepository.Add(new CreateToDoListDto { Description = "buy phone", CreatedBy = 1, UserId = 1, LabelId = 1, IsActive = true }); Assert.IsNotNull(addedtoDoList); Assert.AreEqual("buy phone", addedtoDoList.Description); }
public async Task DeleteToDo(ToDoListDto entityDto) { var existingEntity = await _todoListToDoListManager.GetSiteByIdAsync(entityDto.Id).ConfigureAwait(false); CheckForConcurrency(entityDto, existingEntity);// This should be added in custom dto to entity mapper in actual world await _todoListToDoListManager.DeleteAsync(entityDto.Id).ConfigureAwait(false); }
public async Task AddToDoListTest() { ToDoListDto result = await _toDoListService.Add(new CreateToDoListDto()); Assert.IsNotNull(result); Assert.AreEqual(1, result.ToDoListId); }
public async Task <IActionResult> CreateToDoList(int userId, ToDoListDto toDolistDto) { if (userId != int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value)) { return(Unauthorized()); } var toDoListToCreate = new ToDoList { Name = toDolistDto.Name, CreatedDate = toDolistDto.CreatedDate }; var userFromRepo = await _repo.GetUser(userId); userFromRepo.ToDoLists.Add(toDoListToCreate); if (await _repo.SaveAll()) { return(CreatedAtRoute("", new { userId = userId, id = toDoListToCreate.Id }, toDoListToCreate)); } return(BadRequest("Could not Create to-do list")); }
public async Task UpdateToDoList() { ToDoListDto updatedToDoList = await _toDoListRepository.Update(new UpdateToDoListDto { ToDoListId = 2, Description = "sell phone", UserId = 1, LabelId = 1 }); Assert.IsNotNull(updatedToDoList); Assert.AreEqual("sell phone", updatedToDoList.Description); }
public async Task <IActionResult> Update([Required] int id, UpdateToDoListDto listToUpdate) { int userId = int.Parse(HttpContext.Items["UserId"].ToString()); if (null == listToUpdate || string.IsNullOrWhiteSpace(listToUpdate.Description)) { return(BadRequest(new ResponseModel <string> { IsSuccess = false, Result = "Not Updated.", Message = "Invalid request, Mandatory fields not provided in request." })); } listToUpdate.UserId = userId; listToUpdate.ModifiedBy = userId; ToDoListDto updatedToDoListDto = await _listService.Update(listToUpdate); if (updatedToDoListDto != null) { return(Ok( new ResponseModel <ToDoListDto> { IsSuccess = true, Result = updatedToDoListDto, Message = "ToDoList with Id = " + updatedToDoListDto.ToDoListId + " is updated on " + updatedToDoListDto.ModifiedOn + " by UserId = " + userId + "." })); } return(NotFound( new ResponseModel <object> { IsSuccess = false, Result = "Item to be updated not found.", Message = "No data exist for ToDoListId = " + listToUpdate.ToDoListId })); }
public async Task UpdateToDoList() { ToDoListDto updatedToDoList = await _toDoListDbOps.UpdateToDoList(new UpdateToDoListDto { ToDoListId = 2, Description = "sell phone" }); Assert.IsNotNull(updatedToDoList); Assert.AreEqual("sell phone", updatedToDoList.Description); }
public ResultDto Update(ToDoListDto toDoListDto) { var toDoList = ToDoUnitOfWork.ToDoListRepository .Where(x => x.Id == toDoListDto.Id && x.Status == (int)Status.Active).SingleOrDefault(); if (toDoList == null) { return new ResultDto { HasError = true, Message = "Böyle bir kayıt bulunamadı." } } ; toDoList.Title = toDoListDto.Title; toDoList.Description = toDoListDto.Description; toDoList.Priority = (int)toDoListDto.Priority; toDoList.WorkFlow = (int)toDoListDto.WorkFlow; toDoList.UpdateDate = DateTime.Now; ToDoUnitOfWork.ToDoListRepository.Update(toDoList); ToDoUnitOfWork.Save(); return(new ResultDto { HasError = false }); }
public async Task <IActionResult> PatchToDoList([Required] int id, [FromBody] JsonPatchDocument <UpdateToDoListDto> listToUpdatePatchDoc) { int userId = int.Parse(HttpContext.Items["UserId"].ToString()); if (listToUpdatePatchDoc == null) { return(BadRequest( new ResponseModel <string> { IsSuccess = false, Result = "Bad Request.", Message = "Please try again with correct input." })); } ToDoListDto existingToDoListDto = await _listService.GetById(id, userId); if (existingToDoListDto == null) { return(NotFound( new ResponseModel <string> { IsSuccess = false, Result = "No existing record found for provided input.", Message = "No data exist for Id = " + id })); } var existingUpdateToDoListDto = _mapper.Map <UpdateToDoListDto>(existingToDoListDto); listToUpdatePatchDoc.ApplyTo(existingUpdateToDoListDto); bool isValid = TryValidateModel(existingUpdateToDoListDto); if (!isValid) { return(BadRequest(ModelState)); } existingUpdateToDoListDto.UserId = userId; existingUpdateToDoListDto.ModifiedBy = userId; ToDoListDto updatedToDoListDto = await _listService.Update(existingUpdateToDoListDto); if (updatedToDoListDto == null) { return(NotFound( new ResponseModel <string> { IsSuccess = false, Result = "No existing record found for provided input.", Message = "No data exist for Id = " + id })); } else { return(Ok( new ResponseModel <ToDoListDto> { IsSuccess = true, Result = updatedToDoListDto, Message = "ToDoList record with id =" + updatedToDoListDto.ToDoListId + " is updated on " + updatedToDoListDto.ModifiedOn + " by UserId = " + userId })); } }
public async Task AddToDoList() { ToDoListDto addedtoDoList = await _toDoListDbOps.CreateToDoList(new CreateToDoListDto { Description = "buy phone", CreatedBy = 1 }); Assert.IsNotNull(addedtoDoList); Assert.AreEqual("buy phone", addedtoDoList.Description); }
public async Task GetToDoListById() { ToDoListDto result = await _toDoListContract.GetToDoListById(1, 1); Assert.IsNotNull(result); Assert.AreEqual(1, result.ToDoListId); }
public async Task <ToDoListDto> ChangeListStatusAsync(string userId, string listId) { var list = await this.dbContext.ToDoLists .Include(x => x.ListItems) .FirstOrDefaultAsync(x => x.Id == listId); if (list == null) { throw new ArgumentException(GlobalConstants.ListNotExist); } if (!await this.IsUserOwnListAsync(userId, listId)) { throw new ArgumentException(GlobalConstants.NoPermissionForEditList); } foreach (var li in list.ListItems) { if (list.Status == StatusType.Active) { li.Status = StatusType.Completed; } else { li.Status = StatusType.Active; } } if (list.Status == StatusType.Active) { list.Status = StatusType.Completed; } else { list.Status = StatusType.Active; } var dto = new ToDoListDto() { Id = list.Id, CreatedOn = list.CreatedOn, Name = list.Name, Status = list.Status, ListItems = list.ListItems.Select(x => new ToDoItemDto { Id = x.Id, Name = x.Name, Status = x.Status, CreatedOn = x.CreatedOn, }) .ToList(), }; await this.dbContext.SaveChangesAsync(); return(dto); }
/// <summary> /// Adds ToDoList record /// </summary> /// <param name="createToDoListDto"></param> /// <returns> added ToDoList record. </returns> public async Task <ToDoListDto> AddToDoList(CreateToDoListDto createToDoListDto) { if (createToDoListDto != null) { createToDoListDto.CreatedBy = _userId; } ToDoListDto addedItem = await _toDoListDbOps.CreateToDoList(createToDoListDto); return(addedItem); }
public ActionResult Create(ToDoListDto model) { var result = _toDoListService.Create(model); if (result.HasError) { return(View("Edit", model)); } return(RedirectToAction("List")); }
public ActionResult Edit(ToDoListDto model) { var result = _toDoListService.Update(model); if (result.HasError) { return(View(model)); } ClearCache(model.Id); return(RedirectToAction("List")); }
public ResultDto <ToDoListDto> Create(ToDoListDto toDolistDto) { var toDoList = Mapper.Map <ToDo_List>(toDolistDto); toDoList.Status = (int)Status.Active; ToDoUnitOfWork.ToDoListRepository.Insert(toDoList); ToDoUnitOfWork.Save(); var result = new ResultDto <ToDoListDto> { Data = Mapper.Map <ToDoListDto>(toDoList), HasError = false }; return(result); }
public async Task EditAsync(string userId, ToDoListDto list) { if (!await this.IsUserOwnListAsync(userId, list.Id)) { throw new ArgumentException(GlobalConstants.NoPermissionForEditList); } var targetList = await this.dbContext.ToDoLists.Include(x => x.ListItems).FirstOrDefaultAsync(x => x.Id == list.Id); if (targetList == null) { throw new ArgumentException(GlobalConstants.ListNotExist); } // bool isNullValues = list.ListItems.Any(x => string.IsNullOrWhiteSpace(x.Name) || x == null); // if (isNullValues) // { // throw new ArgumentException(GlobalConstants.ListContainsEmptyItems); // } targetList.Name = list.Name; targetList.Status = list.Status; var itemsToAdd = list.ListItems.Select(li => new ToDoItem { Id = li.Id == null ? Guid.NewGuid().ToString() : li.Id, Name = li.Name, Status = li.Status, ToDoListId = list.Id, CreatedOn = list.CreatedOn, }) .ToHashSet(); foreach (var li in itemsToAdd) { if (string.IsNullOrWhiteSpace(li.Name)) { continue; } targetList.ListItems.Add(li); } await this.dbContext.SaveChangesAsync(); }
public async Task <IActionResult> Add(CreateToDoListDto createToDoList, ApiVersion version) { int userId = int.Parse(HttpContext.Items["UserId"].ToString()); if (createToDoList == null || string.IsNullOrWhiteSpace(createToDoList.Description)) { return(BadRequest(new ResponseModel <string> { IsSuccess = false, Result = "Not Updated.", Message = "Invalid request, mandatory fields not provided in request." })); } createToDoList.CreatedBy = userId; createToDoList.UserId = userId; ToDoListDto createdToDoList = await _listService.Add(createToDoList); return(CreatedAtAction(nameof(GetById), new { id = createdToDoList.ToDoListId, version = $"{version}" }, createdToDoList)); }
public async Task <ToDoListDto> InsertOrUpdateAsync(ToDoListDto entityDto) { var existingEntity = new ToDo.ToDoList(); if (entityDto.Id > 0) { existingEntity = await _todoListToDoListManager.GetSiteByIdAsync(entityDto.Id).ConfigureAwait(false); CheckForConcurrency(entityDto, existingEntity);// This should be added in custom dto to entity mapper in actual world existingEntity = ObjectMapper.Map(entityDto, existingEntity); } else { existingEntity = ObjectMapper.Map <ToDo.ToDoList>(entityDto); } var updatedEntity = await _todoListToDoListManager.InsertOrUpdateAsync(existingEntity).ConfigureAwait(false); return(ObjectMapper.Map <ToDoListDto>(updatedEntity)); }
public async Task <IActionResult> CreateToDoList(CreateToDoListModel createToDoList, ApiVersion version) { long userId = long.Parse(HttpContext.Items["UserId"].ToString()); if (createToDoList == null || string.IsNullOrWhiteSpace(createToDoList.Description)) { return(BadRequest(new ApiResponse <string> { IsSuccess = false, Result = "Not Updated.", Message = "Please enter correct values. Description should not be empty." })); } createToDoList.CreatedBy = userId; CreateToDoListDto createToDoListDto = _mapper.Map <CreateToDoListDto>(createToDoList); ToDoListDto createdToDoList = await _toDoListContract.CreateToDoList(createToDoListDto); return(CreatedAtAction(nameof(GetToDoListById), new { createdToDoList.ToDoListId, version = $"{version}" }, createdToDoList)); }
public async Task <IActionResult> GetById([Required] int id) { int userId = int.Parse(HttpContext.Items["UserId"].ToString()); ToDoListDto toDoListDto = await _listService.GetById(id, userId); if (toDoListDto != null) { return(Ok( new ResponseModel <ToDoListDto> { IsSuccess = true, Result = toDoListDto, Message = "Data retrieval successful." })); } return(NotFound( new ResponseModel <string> { IsSuccess = false, Result = "Not found.", Message = "No data exist for Id = " + id + "." })); }
public async Task <IActionResult> GetToDoListById([Required] long toDoListId) { long userId = long.Parse(HttpContext.Items["UserId"].ToString()); ToDoListDto toDoListDto = await _toDoListContract.GetToDoListById(toDoListId, userId); if (toDoListDto != null) { return(Ok( new ApiResponse <ToDoListDto> { IsSuccess = true, Result = toDoListDto, Message = "ToDoList records retrieval successful." })); } return(NotFound( new ApiResponse <string> { IsSuccess = false, Result = "Not found.", Message = "No data exist for Id = " + toDoListId + "." })); }
public async Task <IActionResult> PutToDoList(UpdateToDoListModel listToUpdate) { long userId = long.Parse(HttpContext.Items["UserId"].ToString()); if (null == listToUpdate || string.IsNullOrWhiteSpace(listToUpdate.Description)) { return(BadRequest(new ApiResponse <string> { IsSuccess = false, Result = "Not Updated.", Message = "Please enter correct values. Description should not be empty." })); } UpdateToDoListDto listToUpdateDto = _mapper.Map <UpdateToDoListDto>(listToUpdate); ToDoListDto updatedToDoListDto = await _toDoListContract.UpdateToDoList(listToUpdateDto); ToDoListModel updatedToDoList = _mapper.Map <ToDoListModel>(updatedToDoListDto); if (updatedToDoList != null) { return(Ok( new ApiResponse <ToDoListModel> { IsSuccess = true, Result = updatedToDoList, Message = "ToDoList with Id = " + updatedToDoList.ToDoListId + " is updated on " + updatedToDoList.UpdationDate + " by UserId = " + userId + "." })); } return(NotFound( new ApiResponse <object> { IsSuccess = false, Result = "Item to be updated not found.", Message = "No data exist for ToDoListId = " + listToUpdate.ToDoListId })); }
public bool Exist(ToDoListDto todoList) { var domain = _mapper.Map <ToDoList>(todoList); return(_toDoListRepository.Exist(domain)); }
public async Task <IActionResult> Edit(ToDoListViewModel list, string returnUrl) { try { if (!this.ModelState.IsValid) { return(this.View(list)); } var user = await this.userManager.GetUserAsync(this.User); var listItems = new List <ToDoItemViewModel>(); if (list.Items.Count() > 0) { listItems.AddRange(list.Items); } foreach (var item in list.ListItems) { var listItemFromStrToViewModel = new ToDoItemViewModel() { Name = item, Status = StatusType.Active, }; listItems.Add(listItemFromStrToViewModel); } list.Items = listItems; var listAsDto = new ToDoListDto() { ListItems = list.Items.Select(x => new ToDoItemDto { Id = x.Id, Name = x.Name, Status = Enum.Parse <MoneySaver.Data.Models.Enums.StatusType>(x.Status.ToString()), }), Id = list.Id, Name = list.Name, Status = Enum.Parse <MoneySaver.Data.Models.Enums.StatusType>(list.Status.ToString()), }; await this.toDoListsService.EditAsync(user.Id, listAsDto); if (returnUrl == "/ToDoLists/AllLists") { return(this.Redirect($"/ToDoLists/AllLists")); } else if (returnUrl == $"/ToDoLists/Edit/{list.Id}") { return(this.Redirect($"/ToDoLists/Edit/{list.Id}")); } return(this.Redirect($"/ToDoLists/AllLists")); } catch (Exception ex) { return(this.Redirect($"/Home/Error?message={ex.Message}")); } }
public async Task <IActionResult> PatchToDoList([Required] long toDoListId, [FromBody] JsonPatchDocument <UpdateToDoListModel> listToUpdatePatchDoc) { long userId = long.Parse(HttpContext.Items["UserId"].ToString()); if (listToUpdatePatchDoc == null) { return(BadRequest( new ApiResponse <string> { IsSuccess = false, Result = "Bad Request.", Message = "Please try again with correct input." })); } ToDoListDto existingToDoListDto = await _toDoListContract.GetToDoListById(toDoListId, userId); if (existingToDoListDto == null) { return(NotFound( new ApiResponse <string> { IsSuccess = false, Result = "No existing record found for provided input.", Message = "No data exist for Id = " + toDoListId })); } JsonPatchDocument <UpdateToDoListDto> PatchToListDto = _mapper.Map <JsonPatchDocument <UpdateToDoListDto> >(listToUpdatePatchDoc); UpdateToDoListDto listToUpdateDto = _mapper.Map <UpdateToDoListDto>(existingToDoListDto); PatchToListDto.ApplyTo(listToUpdateDto); bool isValid = TryValidateModel(listToUpdateDto); if (!isValid) { return(BadRequest(ModelState)); } ToDoListDto updatedToDoListDto = await _toDoListContract.UpdateToDoList(listToUpdateDto); ToDoListModel updatedToDoList = _mapper.Map <ToDoListModel>(updatedToDoListDto); // Dto to Model if (updatedToDoList == null) { return(NotFound( new ApiResponse <string> { IsSuccess = false, Result = "No existing record found for provided input.", Message = "No data exist for Id = " + listToUpdateDto.ToDoListId })); } else { return(Ok( new ApiResponse <ToDoListModel> { IsSuccess = true, Result = updatedToDoList, Message = "ToDoList record with id =" + updatedToDoList.ToDoListId + " is updated on " + updatedToDoList.UpdationDate + " by UserId = " + userId })); } }
public ActionResult Post([FromBody] ToDoListDto toDoList) { _toDoListAppService.Add(toDoList); return(Ok(StatusCodes.Status200OK)); }
/// <summary> /// Update ToDoList record /// </summary> /// <param name="updateToDoListDto"></param> /// <returns> Updated record. </returns> public async Task <ToDoListDto> UpdateToDoList(UpdateToDoListDto updateToDoListDto) { ToDoListDto updatedItem = await _toDoListDbOps.UpdateToDoList(updateToDoListDto); return(updatedItem); }