public IActionResult CreateEnergyExpenditure([FromBody] EnergyExpenditureRequest request) { var expenditure = Mapper.Map <EnergyExpenditure>(request); expenditure.UserId = CurrentUserId; CalculateEnergy(expenditure); activityRepository.CreateEnergyExpenditure(expenditure); var response = Mapper.Map <EnergyExpenditureResponse>(expenditure); return(Ok(response)); }
public IActionResult UpdateEnergyExpenditure(Guid id, [FromBody] EnergyExpenditureRequest request) { var expenditure = activityRepository.GetEnergyExpenditure(id); if (expenditure == null) { return(NotFound()); } if (expenditure.UserId != CurrentUserId) { return(Unauthorized()); } Mapper.Map(request, expenditure); CalculateEnergy(expenditure); activityRepository.UpdateEnergyExpenditure(expenditure); var response = Mapper.Map <EnergyExpenditureResponse>(expenditure); return(Ok(response)); }