public async Task <IActionResult> Update([FromBody] ActionTypeRequestDto actionType) { //Before updating find Action type by id var actionTypeData = await _uow.ActionTypes.GetAsync(actionType.ID); if (actionTypeData != null && actionTypeData.ID > 0) { //Map update data _mapper.Map(actionType, actionTypeData); //Change Modified Data actionTypeData.ModifyDate = DateTime.Now; _uow.ActionTypes.Update(actionTypeData); var result = await _uow.CompleteAsync(); if (result > 0) { //Before returning updated Action type data, map ActionType => ActionTypeSharedDto return(Ok(_mapper.Map <ActionTypeSharedDto>(actionTypeData))); } else { return(new JsonResult(new { Success = false, Message = "Action type changes are not updated" })); } } else { return(NotFound(new { Success = false, Message = "Action type not found with sended details." })); } }
public async Task <ActionTypeSharedDto> Create([FromBody] ActionTypeRequestDto actionType) { //Map dto Action Type object var mappedActionTypeData = _mapper.Map <ActionType>(actionType); //Add not mapped fields mappedActionTypeData.CreateDate = DateTime.Now; mappedActionTypeData.ModifyDate = DateTime.Now; mappedActionTypeData.IsDeleted = false; await _uow.ActionTypes.AddAsync(mappedActionTypeData); var result = await _uow.CompleteAsync(); if (result > 0) { //Map Action Type => ActionTypeSharedDto var resultVehicleType = _mapper.Map <ActionTypeSharedDto>(mappedActionTypeData); return(resultVehicleType); } else { return(null); } }