Exemplo n.º 1
0
        public IHttpActionResult Add(IncomeParam param)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    int      userId  = UserHelper.GetCurrentUserId();
                    DateTime getDate = DateHelper.GetDateTime();

                    param.CreatedDate = getDate;
                    param.CreatedBy   = userId;

                    int id = _incomeService.Add(param);
                    return(Ok(id));
                }
                else
                {
                    string errorResult = string.Join(" ", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage));
                    return(Content(HttpStatusCode.BadRequest, errorResult));
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException == null)
                {
                    return(Content(HttpStatusCode.InternalServerError, ex.Message));
                }
                else
                {
                    return(Content(HttpStatusCode.InternalServerError, ex.InnerException.Message));
                }
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Add(AddIncomeRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(Failure());
            }

            return(await _incomeService.Add(request));
        }
Exemplo n.º 3
0
 public int AddIncome(IncomeViewModel incomeViewModel)
 {
     try
     {
         return(_incomeService.Add(new IncomeControllerHelper().MapIncomeViewModelToDTO(incomeViewModel)));
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
         throw;
     }
 }