Esempio n. 1
0
        public IActionResult Delete(string id)
        {
            TransIncomeModelOutput _incomeModel = new TransIncomeModelOutput();

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

                IncomeServices _income = new IncomeServices
                {
                    objUser = usrSession.UserLog(userId)._userInfo
                };

                var response = _income.Delete(id);

                _incomeModel.IsSuccess = true;
                _incomeModel.Message   = "Success Delete";
                _incomeModel.Code      = 200;
            }
            catch (Exception ex)
            {
                _logger.Error("delete Income" + ex.Message);
                _incomeModel.IsSuccess = false;
                _incomeModel.Message   = "Failed Delete" + ex.Message;
                _incomeModel.Code      = 422;
            }
            return(Ok(_incomeModel));
        }
Esempio n. 2
0
        public IActionResult Store([FromBody] TransIncomeModel model)
        {
            TransIncomeModelOutput _incomeModel = new TransIncomeModelOutput();

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

                    IncomeServices _income = new IncomeServices
                    {
                        objUser = usrSession.UserLog(userId)._userInfo
                    };

                    var response = _income.Add(model);

                    _incomeModel.IsSuccess = true;
                    _incomeModel.Message   = "Success Saving";
                    _incomeModel.Code      = 200;
                }
                else
                {
                    _logger.Error("Post Income");


                    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);

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

            return(Ok(_incomeModel));
        }
Esempio n. 3
0
        public IActionResult Index(PagingParams pagingParams)
        {
            try
            {
                _logger.Information("GetIncome");
                UserSessionManager usrSession = new UserSessionManager();
                var    user   = User as ClaimsPrincipal;
                string userId = user.Claims.Where(c => c.Type == "USERID").Select(c => c.Value).SingleOrDefault();

                IncomeServices _income = new IncomeServices
                {
                    objUser = usrSession.UserLog(userId)._userInfo
                };

                objResponse = _income.GetAll(pagingParams);

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

                var response = new TransIncomeModelOutput
                {
                    IsSuccess  = true,
                    Code       = 200,
                    Message    = "Success Get Expense",
                    Data       = objResponse.List.Select(m => IncomeInfo(m)).ToList(),
                    Pagination = GetLinks(objResponse, "GetIncome")
                };
                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message.ToString());
                var response = new TransIncomeModelOutput
                {
                    IsSuccess = false,
                    Code      = 422,
                    Message   = ex.Message.ToString(),
                };
                return(Ok(response));
            }
        }