Example #1
0
        public async Task <IActionResult> Post([FromBody] EmailAccountViewModel viewModel)
        {
            await AuthorizeHostAsync(EmailAccountFunctionName);

            var entity = viewModel.Map <EmailAccountViewModel, EmailAccount>();
            await _emailAccountService.CreateAsync(entity, GetEmbeddedUser(), GetClientIP());

            return(Created(string.Empty, entity.Id));
        }
Example #2
0
        public async Task <IActionResult> Create(UpdateEmailAccountViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var entity = _mapper.Map <EmailAccount>(viewModel);
                await _emailAccountService.CreateAsync(entity);

                // var activityLog = GetActivityLog(entity.GetType(), newValue: emailAccount);
                // await _activityLogService.CreateAsync(GetSystemKeyword(), activityLog);

                return(RedirectToAction(nameof(Index)));
            }

            return(View("Update", viewModel));
        }
Example #3
0
        public async Task <IActionResult> AddEmailAccount([FromBody] CreateEmailAccount command)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (await _emailAccountService.ExistsByEmailAndUserIdAsync(UserId, command.Email))
            {
                ModelState.AddModelError("Email", "Email address is already taken.");
                return(BadRequest(ModelState));
            }
            try {
                await _emailAccountService.CreateAsync(UserId, command.Email, command.Password, command.ImapHost, command.ImapPort, command.SmtpHost, command.SmtpPort);

                return(StatusCode(201));
            } catch (Exception e) {
                return(BadRequest(e.Message));
            }
        }