Exemple #1
0
        public async Task <ActionResult> Post(ContactCreateInputModel input)
        {
            // var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value;
            var user = await this.userManager.GetUserAsync(this.User);

            var inputId = await this.contactsService.CreateAsync(input, user.Id);

            var model = await this.contactsService.GetByIdAsync <ContactExportModel>(inputId);

            return(this.CreatedAtAction(nameof(this.GetById), new { id = model.Id }, model));
        }
Exemple #2
0
        public async Task <IActionResult> Contact(ContactCreateInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(input));
            }

            this.TempData[GlobalConstants.TempDataContact] = SuccessfulMessage;
            var htmlMessage = new StringBuilder();

            htmlMessage.AppendLine(string.Format(Template, nameof(input.Name), input.Name));
            htmlMessage.AppendLine(string.Format(Template, nameof(input.Email), input.Email));
            htmlMessage.AppendLine(string.Format(Template, nameof(input.Subject), input.Subject));
            htmlMessage.AppendLine(string.Format(Template, nameof(input.Description), input.Description));

            await this.emailSender.SendEmailAsync(Email, input.Subject, htmlMessage.ToString());

            return(this.RedirectToAction(nameof(this.Index)));
        }
        // public async Task CreateAsync(ContactCreateInputModel input, string userId)
        public async Task <int> CreateAsync(ContactCreateInputModel input, string userId)
        {
            // var userEntity = this.usersRepository.AllAsNoTracking()
            //   .FirstOrDefault(x => x.UserName == articleInputModel.UserId);
            //// take the user and record its id in the article, product, conformity, etc.
            // var entity = new Contact
            // {
            //    Icon = input.Icon.Trim(),
            //    Title = input.Title.Trim(),
            //    Link = input.Link.Trim(),
            //    LinkText = input.LinkText.Trim(),
            // };
            var entity = input.To <Contact>();

            await this.contactsRepository.AddAsync(entity);

            await this.contactsRepository.SaveChangesAsync();

            return(entity.Id);
        }