Esempio n. 1
0
        public async Task <IActionResult> LaunchNotifier()
        {
            var launchingUser = await userManager.GetUserAsync(HttpContext.User);

            try
            {
                var mailSendingsToWaitFor = new List <Task>();
                var performanceIndicators = new List <string>();
                var notifierResult        = await new Notifier(callContext, performanceIndicators).RunAsync(new Notifier.Request());
                var sentEmailCount        = 0;

                foreach (var userNotifications in notifierResult.UserNotifications)
                {
                    if (MustSendForNotifications(userNotifications))
                    {
                        var mailBody = GetMailBodyForUser(userNotifications);
                        mailSendingsToWaitFor.Add(emailSender.SendEmailAsync(userNotifications.UserEmail, "MemCheck notifications", mailBody));
                        sentEmailCount++;
                    }
                }

                mailSendingsToWaitFor.Add(emailSender.SendEmailAsync(launchingUser.Email, "Notifier ended on success", GetAdminMailBody(sentEmailCount, performanceIndicators)));
                Task.WaitAll(mailSendingsToWaitFor.ToArray());
                return(ControllerResultWithToast.Success("Notifications sent", this));
            }
            catch (Exception e)
            {
                await emailSender.SendEmailAsync(launchingUser.Email, "Notifier ended on exception", $"<h1>{e.GetType().Name}</h1><p>{e.Message}</p><p><pre>{e.StackTrace}</pre></p>");

                throw;
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> UploadImage([FromForm] UploadImageRequest request)
        {
            if (request.Name == null)
            {
                return(ControllerResultWithToast.FailureWithResourceMesg("NameNotSet", this));
            }
            if (request.Description == null)
            {
                return(ControllerResultWithToast.FailureWithResourceMesg("DescriptionNotSet", this));
            }
            if (request.Source == null)
            {
                return(ControllerResultWithToast.FailureWithResourceMesg("SourceNotSet", this));
            }
            if (request.File == null)
            {
                return(ControllerResultWithToast.FailureWithResourceMesg("FileNotSet", this));
            }

            var userId = await UserServices.UserIdFromContextAsync(HttpContext, userManager);

            using var stream = request.File.OpenReadStream();
            using var reader = new BinaryReader(stream);
            var fileContent        = reader.ReadBytes((int)request.File.Length);
            var applicationRequest = new StoreImage.Request(userId, request.Name.Trim(), request.Description.Trim(), request.Source.Trim(), request.File.ContentType, fileContent);

            await new StoreImage(callContext).RunAsync(applicationRequest);
            return(ControllerResultWithToast.Success($"{Get("ImageSavedWithName")} '{applicationRequest.Name.Trim()}'", this));
        }
Esempio n. 3
0
        public async Task <IActionResult> Update(Guid tagId, [FromBody] UpdateRequestModel request)
        {
            CheckBodyParameter(request);
            var userId = await UserServices.UserIdFromContextAsync(HttpContext, userManager);

            await new UpdateTag(callContext).RunAsync(new UpdateTag.Request(userId, tagId, request.NewName.Trim(), request.NewDescription.Trim()));
            return(ControllerResultWithToast.Success(Get("TagRecorded") + ' ' + request.NewName, this));
        }
Esempio n. 4
0
        public async Task <IActionResult> SetCardRating(Guid cardId, int rating)
        {
            var userId = await UserServices.UserIdFromContextAsync(HttpContext, userManager);

            var request = new SetCardRating.Request(userId, cardId, rating);

            await new SetCardRating(callContext).RunAsync(request);
            return(ControllerResultWithToast.Success($"{Get("RatingSavedOk")} {rating}\u2605", this));
        }
Esempio n. 5
0
        public async Task <IActionResult> DeleteSearchSubscription(Guid id)
        {
            var userId = await UserServices.UserIdFromContextAsync(HttpContext, userManager);

            var appRequest = new DeleteSearchSubscription.Request(userId, id);

            await new DeleteSearchSubscription(callContext).RunAsync(appRequest);
            return(ControllerResultWithToast.Success(Get("Deleted"), this));
        }
Esempio n. 6
0
        public async Task <IActionResult> UpdateCard(Guid cardId, [FromBody] UpdateCardRequest card)
        {
            CheckBodyParameter(card);
            var user = await userManager.GetUserAsync(HttpContext.User);

            var request = new UpdateCard.Request(cardId, user.Id, card.FrontSide, card.FrontSideImageList, card.BackSide, card.BackSideImageList, card.AdditionalInfo, card.AdditionalInfoImageList, card.LanguageId, card.Tags, card.UsersWithVisibility, card.VersionDescription);

            await new UpdateCard(callContext).RunAsync(request);
            return(ControllerResultWithToast.Success(Get("CardSavedOk"), this));
        }
Esempio n. 7
0
        public async Task <IActionResult> RemoveCardFromDeck(Guid deckId, Guid cardId)
        {
            var currentUserId = await UserServices.UserIdFromContextAsync(HttpContext, userManager);

            var query             = new RemoveCardFromDeck.Request(currentUserId, deckId, cardId);
            var applicationResult = await new RemoveCardFromDeck(callContext).RunAsync(query);
            var frontSide         = $" '{applicationResult.FrontSideText.Truncate(30)}'";
            var mesgBody          = Get("CardWithFrontSideHead") + frontSide + ' ' + Get("RemovedFromDeck") + ' ' + applicationResult.DeckName;

            return(ControllerResultWithToast.Success(mesgBody, this));
        }
Esempio n. 8
0
        public async Task <IActionResult> Delete(Guid imageId, [FromBody] DeleteRequest request)
        {
            CheckBodyParameter(request);
            var userId = await UserServices.UserIdFromContextAsync(HttpContext, userManager);

            var applicationRequest = new DeleteImage.Request(userId, imageId, request.DeletionDescription);
            var imageName          = await new DeleteImage(callContext).RunAsync(applicationRequest);
            var toastText          = $"{Get("SuccessfullyDeletedImage")} '{imageName}'";

            return(ControllerResultWithToast.Success(toastText, this));
        }
Esempio n. 9
0
        public async Task <IActionResult> Update(Guid imageId, [FromBody] UpdateRequestModel request)
        {
            CheckBodyParameter(request);
            var userId = await UserServices.UserIdFromContextAsync(HttpContext, userManager);

            var applicationRequest = new UpdateImageMetadata.Request(imageId, userId, request.ImageName, request.Source, request.Description, request.VersionDescription);

            await new UpdateImageMetadata(callContext).RunAsync(applicationRequest);
            var toastText = $"{Get("SuccessfullyUpdatedImage")} '{request.ImageName}'";

            return(ControllerResultWithToast.Success(toastText, this));
        }
Esempio n. 10
0
        public async Task <IActionResult> PostCardOfUser([FromBody] PostCardOfUserRequest card)
        {
            CheckBodyParameter(card);
            var userId = await UserServices.UserIdFromContextAsync(HttpContext, userManager);

            var versionDescription = Get("InitialCardVersionCreation");
            var request            = new CreateCard.Request(userId, card.FrontSide !, card.FrontSideImageList, card.BackSide !, card.BackSideImageList, card.AdditionalInfo !, card.AdditionalInfoImageList, card.LanguageId, card.Tags, card.UsersWithVisibility, versionDescription);
            var cardId             = (await new CreateCard(callContext).RunAsync(request)).CardId;

            if (card.AddToDeck != Guid.Empty)
            {
                await new AddCardsInDeck(callContext).RunAsync(new AddCardsInDeck.Request(userId, card.AddToDeck, cardId.AsArray()));
            }
            return(ControllerResultWithToast.Success(Get("CardSavedOk"), this));
        }