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
            }));
        }
        /// <summary>
        /// Updates the specified to do list dto.
        /// </summary>
        /// <param name="toDoListDto">To do list dto.</param>
        /// <returns></returns>
        public async Task <ToDoListDto> Update(UpdateToDoListDto toDoListDto)
        {
            ToDoList toDoListDb = await _toDoListRepository.FilterList(x => x.ToDoListId == toDoListDto.ToDoListId && x.UserId == toDoListDto.UserId && x.IsActive.Value).FirstOrDefaultAsync();

            if (toDoListDb == null)
            {
                return(null);
            }

            ToDoList toDoList = _mapper.Map <ToDoList>(toDoListDto);

            toDoList.CreatedBy  = toDoListDb.CreatedBy;
            toDoList.CreatedOn  = toDoListDb.CreatedOn;
            toDoList.ModifiedBy = toDoListDto.UserId;
            toDoList.ModifiedOn = DateTime.UtcNow;
            if (!toDoList.IsActive.HasValue)
            {
                toDoList.IsActive = toDoListDb.IsActive;
            }

            _toDoListRepository.Update(toDoList);
            await _toDoListRepository.Save();

            return(_mapper.Map <ToDoListDto>(toDoList));
        }
Пример #3
0
        /// <summary>
        /// Update ToDoListId.
        /// </summary>
        /// <param name="updateToDoListDto"></param>
        /// <returns> Updated ToDoListId. </returns>
        public async Task <ToDoListDto> UpdateToDoList(UpdateToDoListDto updateToDoListDto)
        {
            ToDoListDbModel toDoListDbModel = await _toDoDbContext.ToDoLists
                                              .FirstOrDefaultAsync(p => p.ToDoListId == updateToDoListDto.ToDoListId);

            if (toDoListDbModel == null)
            {
                return(null);
            }
            toDoListDbModel.Description  = updateToDoListDto.Description;
            toDoListDbModel.UpdationDate = DateTime.UtcNow;
            await _toDoDbContext.SaveChangesAsync();

            return(_mapper.Map <ToDoListDto>(toDoListDbModel));
        }
Пример #4
0
        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
            }));
        }
Пример #5
0
 /// <summary>
 /// Update specified ToDoList record.
 /// </summary>
 /// <param name="updateToDoListDto">Description,UpdationDate,ToDoListId</param>
 /// <returns> Updated ToDoList record ,</returns>
 public async Task <ToDoListDto> UpdateToDoList(UpdateToDoListDto updateToDoListDto)
 {
     return(await _toDoListDbOps.UpdateToDoList(updateToDoListDto));
 }
Пример #6
0
        /// <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);
        }
 /// <summary>
 /// Updates the specified to do list dto.
 /// </summary>
 /// <param name="toDoListDto">To do list dto.</param>
 /// <returns></returns>
 public async Task <ToDoListDto> Update(UpdateToDoListDto toDoListDto)
 {
     return(await _toDoListRepository.Update(toDoListDto));
 }
Пример #8
0
        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
                }));
            }
        }