Exemple #1
0
        public async Task <ContactFormServiceModel> GetByIdAsync(string id)
        {
            var email = await this.context.ContactForms.FindAsync(id);

            var model = new ContactFormServiceModel
            {
                Id      = email.Id,
                Name    = email.Name,
                Email   = email.Email,
                Subject = email.Subject,
                Message = email.Message,
            };

            return(model);
        }
Exemple #2
0
        public async Task <bool> CreateContactFormAsync(ContactFormServiceModel contactFormServiceModel)
        {
            var model = new ContactForm
            {
                Name    = contactFormServiceModel.Name,
                Subject = contactFormServiceModel.Subject,
                Message = contactFormServiceModel.Message,
                Email   = contactFormServiceModel.Email,
            };

            await this.context.ContactForms.AddAsync(model);

            var result = await this.context.SaveChangesAsync();

            return(result > 0);
        }
Exemple #3
0
        public async Task <IActionResult> Delete(int id, ContactFormServiceModel model)
        {
            try
            {
                var success = await this.contactService.DeleteAsync(id);

                if (!success)
                {
                    return(NotFound());
                }

                return(RedirectToAction(nameof(All)));
            }
            catch
            {
                return(View());
            }
        }
        public async Task <ContactFormServiceModel> CreateModelAsync(int id)
        {
            var contact = await this.FindByIdAsync(id);

            contact.IsSeen = true;

            await this.db.SaveChangesAsync();

            var model = new ContactFormServiceModel
            {
                Name    = contact.Name,
                Email   = contact.Email,
                Subject = contact.Subject,
                Message = contact.Message,
                IsSeen  = contact.IsSeen
            };

            return(model);
        }
        public async Task <IActionResult> Contact(ContactFormInputModel contactFormInputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View());
            }

            var model = new ContactFormServiceModel
            {
                Name    = contactFormInputModel.Name,
                Subject = contactFormInputModel.Subject,
                Email   = contactFormInputModel.Email,
                Message = contactFormInputModel.Message,
            };

            await this.informationsService.CreateContactFormAsync(model);

            return(this.Redirect("/"));
        }
Exemple #6
0
        public async Task <IActionResult> Create(ContactFormServiceModel model)
        {
            if (!ModelState.IsValid)
            {
                TempData["Message"] = "There was a problem with your contact data";
                return(View());
            }
            try
            {
                await this.contactService
                .CreateAsync(model.Name, model.Email, model.Subject, model.Message);

                TempData["Message"] = "Your contact form has been send";
                return(View());
            }
            catch
            {
                TempData["Message"] = "There was a problem with your contact data";
                return(View());
            }
        }