Exemplo n.º 1
0
        public IActionResult Update([FromBody] SettingModel 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();
            SettingModelOutput settingModelOutput = new SettingModelOutput();

            try
            {
                _logger.Information("Saving Update setting");
                if (ModelState.IsValid)
                {
                    SettingServices settingServices = new SettingServices
                    {
                        objUser = usrSession.UserLog(userId)._userInfo
                    };

                    var res = settingServices.Update(request, id);
                    settingModelOutput.IsSuccess = true;
                    settingModelOutput.Message   = "Success Update";
                    settingModelOutput.Code      = 200;
                }
                else
                {
                    _logger.Error("Error Update Setting");


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

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

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


                DisplaySetting displaySetting = new DisplaySetting
                {
                    objUser = usrSession.UserLog(userId)._userInfo
                };
                var query = new List <SettingModel>((List <SettingModel>)displaySetting.Display()).ToList();

                var response = new SettingModelOutput
                {
                    IsSuccess = true,
                    Code      = 200,
                    Message   = "Success",
                    Data      = query
                };


                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message.ToString());
                var response = new SettingModelOutput
                {
                    IsSuccess = false,
                    Code      = 422,
                    Message   = ex.Message.ToString(),
                };
                return(Ok(response));
            }
        }