public async Task <ActionResult> SubmitChatKarma(string chatHandle, int chatMessageId) { using (var context = new ApplicationDbContext()) { var senderId = User.Identity.GetUserId(); var sender = await context.Users.FirstOrDefaultAsync(x => x.Id == senderId).ConfigureAwait(false); if (sender == null) { return(Json(new { Success = false, Message = Resources.Layout.karmaErrorUnauthorizedMessage })); } var user = await context.Users.FirstOrDefaultAsync(x => x.ChatHandle == chatHandle || x.UserName == chatHandle).ConfigureAwait(false); if (user == null) { return(Json(new { Success = false, Message = Resources.Layout.karmaErrorUserNotFoundMessage })); } if (!await context.ChatMessages.AnyAsync(x => x.Id == chatMessageId && x.UserId == user.Id).ConfigureAwait(false)) { return(Json(new { Success = false, Message = Resources.Layout.karmaChatErrorMessageNotFoundMessage })); } var maxTimestamp = DateTime.UtcNow.AddHours(-24); if (await context.UserKarma.CountAsync(x => x.SenderId == sender.Id && x.KarmaType == UserKarmaType.Chat && x.Timestamp > maxTimestamp).ConfigureAwait(false) >= 20) { return(Json(new { Success = false, Message = Resources.Layout.karmaChatErrorLimitMessage })); } var karma = new UserKarma { KarmaType = UserKarmaType.Chat, UserId = user.Id, SenderId = sender.Id, Discriminator = chatMessageId.ToString() }; if (!await SaveKarmaChanges(context, user, karma)) { return(Json(new { Success = false, Message = string.Format(Resources.Layout.karmaChatErrorAlreadySentMessage, chatHandle) })); } await SendKarmaNotification(context, user, string.Format(Resources.Layout.karmaChatNotificationMessage, sender.ChatHandle)); await ChatHub.InvalidateUserCache(user.Id); return(Json(new { Success = true, Message = string.Format(Resources.Layout.karmaChatIsSentMessage, chatHandle), User = user.UserName, Count = user.KarmaTotal })); } }
public async Task <ActionResult> SubmitTipKarma(string chatHandle, int chatMessageId) { using (var context = new ApplicationDbContext()) { var senderId = User.Identity.GetUserId(); var sender = await context.Users.FirstOrDefaultAsync(x => x.Id == senderId).ConfigureAwait(false); if (sender == null) { return(Json(new { Success = false, Message = Resources.Layout.karmaErrorUnauthorizedMessage })); } var user = await context.Users.FirstOrDefaultAsync(x => x.ChatHandle == chatHandle || x.UserName == chatHandle).ConfigureAwait(false); if (user == null) { return(Json(new { Success = false, Message = Resources.Layout.karmaErrorUserNotFoundMessage })); } var chatBotId = Constant.SYSTEM_USER_CHATBOT.ToString(); var tip = await context.ChatMessages.FirstOrDefaultAsync(x => x.Id == chatMessageId && x.UserId == chatBotId).ConfigureAwait(false); if (tip == null || tip.Message.Split(':')[1] != chatHandle) { return(Json(new { Success = false, Message = Resources.Layout.karmaTipErrorNotFoundMessage })); } var karma = new UserKarma { KarmaType = UserKarmaType.Tip, UserId = user.Id, SenderId = sender.Id, Discriminator = chatMessageId.ToString() }; if (!await SaveKarmaChanges(context, user, karma)) { return(Json(new { Success = false, Message = string.Format(Resources.Layout.karmaTipErrorAlreadySentMessage, chatHandle) })); } await SendKarmaNotification(context, user, string.Format(Resources.Layout.karmaTipNotificationMessage, sender.ChatHandle)); await ChatHub.InvalidateUserCache(user.Id); return(Json(new { Success = true, Message = string.Format(Resources.Layout.karmaTipIsSentMessage, chatHandle), User = user.UserName, Count = user.KarmaTotal })); } }
public async Task <ActionResult> SubmitTipIgnore(string username) { var result = await UserSettingsWriter.UpdateIgnoreList(User.Identity.GetUserId(), UserIgnoreListType.Tip, username); if (result.Success) { await ChatHub.InvalidateUserCache(User.Identity.GetUserId()); } return(Json(new { Success = result.Success, Message = result.Message, WasRemoved = result.Result })); }
public async Task <ActionResult> UpdateUser(AdminUserUpdateModel model) { if (!ModelState.IsValid) { return(View("UpdateUserModal", model)); } var result = await AdminUserWriter.UpdateUser(model).ConfigureAwait(false); if (!ModelState.IsWriterResultValid(result)) { return(View("UpdateUserModal", model)); } await ChatHub.InvalidateUserCache(model.UserId); return(CloseModalSuccess(result.Message)); }
public async Task <ActionResult> UpdateSettings(UserSettingsModel model) { if (!ModelState.IsValid) { return(PartialView("_Settings", model)); } var result = await UserSettingsWriter.UpdateSettings(User.Identity.GetUserId(), model); if (!ModelState.IsWriterResultValid(result)) { return(PartialView("_Settings", model)); } User.UpdateClaim(CryptopiaClaim.Theme, model.Theme.ToString()); await ChatHub.InvalidateUserCache(User.Identity.GetUserId()); return(PartialView("_Settings", model)); }
public async Task <ActionResult> UpdateProfile(UserProfileModel model) { if (!ModelState.IsValid) { return(PartialView("_Profile", model)); } var result = await UserProfileWriter.UpdateProfile(User.Identity.GetUserId(), model); if (!ModelState.IsWriterResultValid(result)) { return(PartialView("_Profile", model)); } User.UpdateClaim(CryptopiaClaim.ChatHandle, model.ChatHandle); await ChatHub.InvalidateUserCache(User.Identity.GetUserId()); return(PartialView("_Profile", model)); }
public async Task <ActionResult> UpdateAvatar(HttpPostedFileBase AvatarFile) { var result = await ImageService.SaveImage(new CreateImageModel { Name = User.Identity.GetUserName(), Directory = HostingEnvironment.MapPath("~/Content/Images/Avatar"), FileStream = AvatarFile.InputStream, MaxHeight = 60, MaxWidth = 60, MaxFileSize = 200 * 1024, CanResize = true }); if (!result.Success) { return(ViewMessage(new ViewMessageModel(ViewMessageType.Danger, Resources.User.profileAvatarErrorTitle, result.Message, showContinueLink: true, continueLink: Url.RouteUrl("Account"), continueLinkText: Resources.User.profileAvatarErrorLink))); } await ChatHub.InvalidateUserCache(User.Identity.GetUserId()); return(RedirectToRoute("Account")); }