public async Task <IActionResult> Post([FromBody] Models.Plan plan) { if (plan == null) { //_logger.LogInformation($"User is empty when accessing to UserController/Post(UserDto plan)."); return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var planEntity = _mapper.Map <Entities.Plan>(plan); await _planRepository.AddAsync(planEntity); if (!await _planRepository.SaveAsync()) { // _logger.LogError($"Add User is not valid. Error in SaveAsync(). When accessing to UserController/Post"); return(StatusCode(500, "A problem happend while handling your request.")); } //TODO: Implement Realistic Implementation return(Created("", null)); }
public async Task <PlanResponse> SaveAsync(Plan plan) { try { await _planRepository.AddAsync(plan); await _unitOfWork.CompleteAsync(); return(new PlanResponse(plan)); } catch (Exception ex) { return(new PlanResponse($"An error ocurred while saving plan: {ex.Message}")); } }
public async Task <IResult <long> > AddAsync(PlanModel model) { var validation = await new AddPlanModelValidator().ValidateAsync(model); if (validation.Failed) { return(Result <long> .Fail(validation.Message)); } var user = await _userRepository.GetAsync(model.UserId); var plan = PlanFactory.CreatePlan(model, user); await _repository.AddAsync(plan); await _unitOfWork.SaveChangesAsync(); return(Result <long> .Success(plan.Id)); }