Ejemplo n.º 1
0
        public IActionResult Update([FromBody] AccountModel request, string id)
        {
            UserSessionManager usrSession         = new UserSessionManager();
            var                user               = User as ClaimsPrincipal;
            string             userId             = user.Claims.Where(c => c.Type == "USERID").Select(c => c.Value).SingleOrDefault();
            AccountModelOutput accountModelOutput = new AccountModelOutput();

            try
            {
                _logger.Information("Saving Update Account");
                if (ModelState.IsValid)
                {
                    AccountServices accountServices = new AccountServices
                    {
                        objUser = usrSession.UserLog(userId)._userInfo
                    };

                    var res = accountServices.Update(request, id);
                    accountModelOutput.IsSuccess = true;
                    accountModelOutput.Message   = "Success Upate";
                    accountModelOutput.Code      = 200;
                }
                else
                {
                    _logger.Error("ErrorUpdate Account");


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

                    accountModelOutput.IsSuccess   = false;
                    accountModelOutput.Message     = "error Update Account validating";
                    accountModelOutput.Code        = 422;
                    accountModelOutput.CustomField = dict;
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message.ToString());
                accountModelOutput.IsSuccess = false;
                accountModelOutput.Message   = "Failed Update Account" + ex.Message;
                accountModelOutput.Code      = 422;
            }

            return(Ok(accountModelOutput));
        }
Ejemplo n.º 2
0
        public IActionResult Index(PagingParams pagingParams)
        {
            try
            {
                _logger.Information("Get Account");
                UserSessionManager usrSession = new UserSessionManager();
                var    user   = User as ClaimsPrincipal;
                string userId = user.Claims.Where(c => c.Type == "USERID").Select(c => c.Value).SingleOrDefault();

                AccountServices accountServices = new AccountServices
                {
                    objUser = usrSession.UserLog(userId)._userInfo
                };

                objResponse = accountServices.GetAll(pagingParams);
                Response.Headers.Add("X-Pagination", objResponse.GetHeader().ToJson());
                var response = new AccountModelOutput
                {
                    IsSuccess  = true,
                    Code       = 200,
                    Message    = "Success Get Account",
                    Data       = objResponse.List.Select(m => ToAccountInfo(m)).ToList(),
                    Pagination = GetLinks(objResponse, "GetAccount")
                };
                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message.ToString());
                var response = new AccountModelOutput
                {
                    IsSuccess = false,
                    Code      = 422,
                    Message   = ex.Message.ToString(),
                };
                return(Ok(response));
            }
        }