public async Task <IActionResult> Put(DTOModels.Income editedIncome) { try { if (!ModelState.IsValid) { return(BadRequest()); } var income = modelTransformer.FromDTOModelIncomeToModelIncome(editedIncome); var savedIncome = await repository.UpdateIncome(income); if (savedIncome == null) { return(StatusCode((int)HttpStatusCode.InternalServerError, ServerMessages.INTERNAL_SERVER_ERROR)); } return(StatusCode((int)HttpStatusCode.Created, modelTransformer.FromModelIncomeToDTOModelIncome(savedIncome))); } catch (Exception ex) { logger.LogError(ex); return(StatusCode((int)HttpStatusCode.InternalServerError, ServerMessages.INTERNAL_SERVER_ERROR)); } }
public Models.Income FromDTOModelIncomeToModelIncome(DTOModels.Income income) { if (income == null) { throw new ArgumentNullException(nameof(income)); } var modelIncome = new Models.Income(); modelIncome.Amount = income.Amount; modelIncome.Comment = income.Comment; modelIncome.Date = income.Date; modelIncome.Id = income.Id; modelIncome.PayTypeId = income.PayTypeId; return(modelIncome); }
public DTOModels.Income FromModelIncomeToDTOModelIncome(Models.Income income) { if (income == null) { throw new ArgumentNullException(nameof(income)); } var dtoIncome = new DTOModels.Income(); dtoIncome.Amount = income.Amount; dtoIncome.Comment = income.Comment; dtoIncome.Date = income.Date; dtoIncome.Id = income.Id; dtoIncome.PayType = income.PayType?.Name; dtoIncome.PayTypeId = income.PayTypeId; dtoIncome.AmountToDisplay = income.Amount.ToString("N2"); dtoIncome.ShortComment = income.Comment?.Length > 10 ? income.Comment.Substring(10) : income.Comment; return(dtoIncome); }