Exemplo n.º 1
0
        public async Task <bool?> UpdateUserPrivacy([NotNull] UserPrivacy userPrivacy)
        {
            var userPrivacyId = await GetUserPrivacyOrAppSettingIdByUserId(userPrivacy.UserId);

            if (userPrivacyId == null)
            {
                return(null);
            }

            userPrivacy.Id = userPrivacyId.Value;
            _dbContext.UserPrivacies.Update(userPrivacy);
            try {
                var result = await _dbContext.SaveChangesAsync();

                return(result != 0);
            }
            catch (DbUpdateException e) {
                await _coreLogService.InsertRoutinizeCoreLog(new RoutinizeCoreLog {
                    Location            = $"{ nameof(UserService) }.{ nameof(UpdateUserPrivacy) }",
                    Caller              = $"{ new StackTrace().GetFrame(4)?.GetMethod()?.DeclaringType?.FullName }",
                    BriefInformation    = nameof(DbUpdateException),
                    DetailedInformation = $"Error while updating entry to UserPrivacies.\n\n{ e.StackTrace }",
                    ParamData           = $"{ nameof(userPrivacy) } = { JsonConvert.SerializeObject(userPrivacy) }",
                    Severity            = SharedEnums.LogSeverity.High.GetEnumValue()
                });

                return(null);
            }
        }
        public async Task <JsonResult> UpdateUserPrivacy([FromHeader] int accountId, [FromBody] UserPrivacy userPrivacy)
        {
            if (userPrivacy.UserId < 1)
            {
                var saveProfileResult = await _userService.InsertBlankUserWithPrivacyAndAppSetting(accountId);

                if (!saveProfileResult.HasValue || saveProfileResult < 1)
                {
                    return(new JsonResult(new JsonResponse {
                        Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while updating data."
                    }));
                }

                userPrivacy.UserId = saveProfileResult.Value;
            }

            var updatePrivacyResult = await _userService.UpdateUserPrivacy(userPrivacy);

            return(updatePrivacyResult.HasValue && updatePrivacyResult.Value
                ? new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Success, Data = userPrivacy.UserId
            })
                : new JsonResult(new JsonResponse {
                Result = SharedEnums.RequestResults.Failed, Message = "An issue happened while updating data."
            }));
        }
Exemplo n.º 3
0
        public void SavePrivacy()
        {
            Boolean isUserPrivacyClose = Component.IsClose(typeof(UserPrivacy));

            if (isUserPrivacyClose)
            {
                echo("对不起,本功能已经停用");
                return;
            }

            //---------------------------------------------------------


            User user = ctx.owner.obj as User;

            if (user == null)
            {
                echoRedirect(lang("exUser"));
                return;
            }

            Dictionary <string, int> settings = UserSecurity.GetSettingsAll(user);
            Dictionary <string, int> values   = new Dictionary <string, int>();

            foreach (KeyValuePair <string, int> s in settings)
            {
                int val = UserPrivacy.GetDefaultValue();
                if (ctx.PostHas(s.Key))
                {
                    val = ctx.PostInt(s.Key);
                }

                values.Add(s.Key, val);
            }

            String settingsStr = UserSecurity.Save(values);


            user.Security = settingsStr;
            db.update(user, "Security");

            echoRedirect(lang("opok"));
        }