public IHttpActionResult Update(int id, [FromBody] BudgetParam param) { try { if (ModelState.IsValid) { int userId = UserHelper.GetCurrentUserId(); DateTime getDate = DateHelper.GetDateTime(); param.UpdatedDate = getDate; param.UpdatedBy = userId; int result = _budgetService.Update(id, param); return(Ok(result)); } 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)); } } }
public int Update(int id, BudgetParam param) { var model = _budgetRepository.Get(id); Validate.NotNull(model, "Budget name is not found."); isExisit(id, param.BudgetName); using (_unitOfWork) { model.Update(param.BudgetName, param.Definition, param.UpdatedBy, param.UpdatedDate); _budgetRepository.Update(model); _unitOfWork.Commit(); } return(model.Id); }
public int Add(BudgetParam param) { int id = 0; Validate.NotNull(param.BudgetName, "Budget name is required."); isExisit(param.BudgetName); using (_unitOfWork) { Budget model = new Budget(param.BudgetName, param.Definition, param.CreatedBy, param.CreatedDate); _budgetRepository.Insert(model); _unitOfWork.Commit(); id = model.Id; } return(id); }