Exemplo n.º 1
0
        public IActionResult Delete(string id)
        {
            TransExpenseModelOutput _expenseModel = new TransExpenseModelOutput();

            try
            {
                _logger.Information("Delete Expense " + id);
                UserSessionManager usrSession = new UserSessionManager();
                var    user   = User as ClaimsPrincipal;
                string userId = user.Claims.Where(c => c.Type == "USERID").Select(c => c.Value).SingleOrDefault();

                ExpenseServices _expense = new ExpenseServices
                {
                    objUser = usrSession.UserLog(userId)._userInfo
                };

                var response = _expense.Delete(id);

                _expenseModel.IsSuccess = true;
                _expenseModel.Message   = "Success Delete";
                _expenseModel.Code      = 200;
            }
            catch (Exception ex)
            {
                _logger.Error("delete Expense" + ex.Message);
                _expenseModel.IsSuccess = false;
                _expenseModel.Message   = "Failed Delete" + ex.Message;
                _expenseModel.Code      = 422;
            }
            return(Ok(_expenseModel));
        }
Exemplo n.º 2
0
        public IActionResult Update([FromBody] TransExpenseModel model, string id)

        {
            TransExpenseModelOutput _expenseModel = new TransExpenseModelOutput();

            try
            {
                if (ModelState.IsValid)
                {
                    _logger.Information("update Post Expense");
                    UserSessionManager usrSession = new UserSessionManager();
                    var    user   = User as ClaimsPrincipal;
                    string userId = user.Claims.Where(c => c.Type == "USERID").Select(c => c.Value).SingleOrDefault();

                    ExpenseServices _expense = new ExpenseServices
                    {
                        objUser = usrSession.UserLog(userId)._userInfo
                    };

                    var response = _expense.Update(model, id);

                    _expenseModel.IsSuccess = true;
                    _expenseModel.Message   = "Success Saving";
                    _expenseModel.Code      = 200;
                }
                else
                {
                    _logger.Error("update Expense");


                    string errordetails = "";
                    var    errors       = new List <string>();
                    foreach (var state in ModelState)
                    {
                        foreach (var error in state.Value.Errors)
                        {
                            string p = error.ErrorMessage;
                            errordetails = errordetails + error.ErrorMessage;
                        }
                    }
                    Dictionary <string, object> dict = new Dictionary <string, object>();
                    dict.Add("error", errordetails);

                    _expenseModel.IsSuccess   = false;
                    _expenseModel.Message     = "error update saving validating";
                    _expenseModel.Code        = 422;
                    _expenseModel.CustomField = dict;
                }
            }
            catch (Exception ex)
            {
                _logger.Error("update Post Expense" + ex.Message);
                _expenseModel.IsSuccess = false;
                _expenseModel.Message   = "Failed update" +
                                          " Saving" + ex.Message;
                _expenseModel.Code = 422;
            }

            return(Ok(_expenseModel));
        }
Exemplo n.º 3
0
        public ActionResult UpdateExpense(ExpenseVM model)
        {
            try
            {
                ExpenseServices.Update(model, BPARepo);

                return(RedirectToAction("Expense", new { budgetId = model.BudgetId }));
            }
            catch (Exception ex)
            {
                SetViewError(ex);
                return(View(model));
            }
        }
Exemplo n.º 4
0
        public IActionResult Index(PagingParams pagingParams)
        {
            try
            {
                _logger.Information("GetExpense");
                UserSessionManager usrSession = new UserSessionManager();
                var    user   = User as ClaimsPrincipal;
                string userId = user.Claims.Where(c => c.Type == "USERID").Select(c => c.Value).SingleOrDefault();

                ExpenseServices _expense = new ExpenseServices
                {
                    objUser = usrSession.UserLog(userId)._userInfo
                };

                objResponse = _expense.GetAll(pagingParams);

                Response.Headers.Add("X-Pagination", objResponse.GetHeader().ToJson());

                var response = new TransExpenseModelOutput
                {
                    IsSuccess  = true,
                    Code       = 200,
                    Message    = "Success Get Expense",
                    Data       = objResponse.List.Select(m => ExpenseInfo(m)).ToList(),
                    Pagination = GetLinks(objResponse, "GetExpense")
                };
                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message.ToString());
                var response = new TransExpenseModelOutput
                {
                    IsSuccess = false,
                    Code      = 422,
                    Message   = ex.Message.ToString(),
                };
                return(Ok(response));
            }
        }
Exemplo n.º 5
0
        public ActionResult UpdateExpense(int id)
        {
            var model = ExpenseServices.GetById(id, BPARepo);

            return(View(model));
        }
Exemplo n.º 6
0
        public ActionResult CreateExpense(int budgetId)
        {
            var model = ExpenseServices.GetNew(BPARepo, budgetId);

            return(View(model));
        }