Пример #1
0
        public async Task <ActionResult> CreateAsync(ContactPersonViewModel person)
        {
            if (!ModelState.IsValid)
            {
                return(View(person));
            }

            var sessionId         = HttpContext.GetSessionId();
            var resumeAttachments =
                await _resumeManager.GetFilesAsync(sessionId, MimeTypeId.Pdf).ConfigureAwait(false);

            var codeExamplesAttachments =
                await _resumeManager.GetFilesAsync(sessionId, MimeTypeId.Zip).ConfigureAwait(false);

            // TOREFACTOR: Отправка почты - довольно долгая операция, которая может привести к таймауту (с дальнейшей отменой операции):
            // стоит предусмотреть очередь на отправку, вместо фактического ожидания
            var contactUsResult =
                await
                _contactSender.ContactUsAsync(
                    person, resumeAttachments, codeExamplesAttachments, _credentials, _recipients).ConfigureAwait(false);

            if (contactUsResult)
            {
                /*var deletedCount = */ await _resumeManager.DeleteAsync(sessionId).ConfigureAwait(false);

                TempData[TempDataContants.NotificationKey] = Resources.ContactUsController_SuccessfullySent;
                return(RedirectToAction("Index", "Home"));
            }

            ModelState.AddModelError(string.Empty, Resources.ContactUsController_ErrorSendingEmail);

            return(View(person));
        }
        public async Task <HttpResponseMessage> DeleteAsync(FormDataCollection formData)
        {
            var context             = HttpContext.Current;
            var fileName            = formData[FileFormDataKey];
            var sessionId           = context.GetSessionId();
            var successfullyDeleted =
                await _resumeManagerRepository.DeleteAsync(sessionId, fileName).ConfigureAwait(false);

            if (!successfullyDeleted)
            {
                return(new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    ReasonPhrase = string.Format(Resources.FileNotExists, fileName)
                });
            }

            return(new HttpResponseMessage(HttpStatusCode.OK)
            {
                ReasonPhrase = string.Format(Resources.FileSuccessfullyDeleted, fileName)
            });
        }