public async Task <IActionResult> Update([FromBody] PictureGroupRequestDto pictureGroup) { //Before updating find Picture Group by id var pictureGroupData = await _uow.PictureGroups.GetAsync(pictureGroup.ID); if (pictureGroupData != null && pictureGroupData.ID > 0) { //Map update data _mapper.Map(pictureGroup, pictureGroupData); //Change Modified Data pictureGroupData.ModifyDate = DateTime.Now; _uow.PictureGroups.Update(pictureGroupData); var result = await _uow.CompleteAsync(); if (result > 0) { //Before returning updated Picture Group data, map PictureGroup => PictureGroupSharedDto return(Ok(_mapper.Map <PictureGroupSharedDto>(pictureGroupData))); } else { return(new JsonResult(new { Success = false, Message = "Picture Group changes are not updated" })); } } else { return(NotFound(new { Success = false, Message = "Picture Group not found with sended details." })); } }
public async Task <PictureGroupSharedDto> Create([FromBody] PictureGroupRequestDto pictureGroup) { //Map dto Picture Group object var mappedPictureGroupData = _mapper.Map <PictureGroup>(pictureGroup); //Add not mapped fields mappedPictureGroupData.CreateDate = DateTime.Now; mappedPictureGroupData.ModifyDate = DateTime.Now; mappedPictureGroupData.IsDeleted = false; var pictureGroupDetails = await _uow.PictureGroups.AddAsync(mappedPictureGroupData); var result = await _uow.CompleteAsync(); if (result > 0) { //Map PictureGroup => PictureGroupSharedDto var resultVehicleType = _mapper.Map <PictureGroupSharedDto>(pictureGroupDetails); return(resultVehicleType); } else { return(null); } }