Exemplo n.º 1
0
        public IActionResult Add(int customerId, [FromBody] ContactFormDto contactDto)
        {
            var contact = _contactAppService.Add(customerId, contactDto);

            if (contact == null)
            {
                return(NotFound());
            }

            return(StatusCode(StatusCodes.Status201Created, contact));
        }
Exemplo n.º 2
0
        public async Task <bool> SaveContactForm(ContactFormDto contactFormDto)
        {
            ContactForm contactForm = new ContactForm
            {
                Name    = contactFormDto.Name,
                Email   = contactFormDto.Email,
                Contact = contactFormDto.Contact
            };

            await _context.ContactForms.AddAsync(contactForm);

            return(await _context.SaveChangesAsync() > 0);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> PostContactMessageAsync(ContactFormDto model)
        {
            try
            {
                var templateModel = new { name = model.Name, email = model.Email, message = model.Message };
                await _emailSender.SendTemplateEmail("d-55cc650c1ace438d81e5aa53df1aaf4d", "*****@*****.**", templateModel);

                return(Ok(model));
            }
            catch (Exception ex)
            {
                _logger.LogError(LoggingEvents.GetListNotFound, ex, "an exception was raised");
                return(StatusCode(500, "an unexpected error occurred"));
            }
        }
Exemplo n.º 4
0
        public async Task <IActionResult> PostMessage(ContactFormDto dto)
        {
            if (dto == null)
            {
                return(BadRequest("You tried to send a message without providing any data."));
            }

            var success = await _messageService.SendMessage(dto);

            if (success)
            {
                return(Ok("Message successfully sent."));
            }

            throw new Exception("There was an error sending the message.");
        }
Exemplo n.º 5
0
        public ContactFormDto EditContactForm(ContactFormDto contactFormDto, int userId, int tenantId)
        {
            var conatctFormObj = _conatctFormService.Query(x => x.InqueryId == contactFormDto.InqueryId).Select().FirstOrDefault();

            if (conatctFormObj == null)
            {
                throw new NotFoundException(ErrorCodes.ProductNotFound);
            }


            //  conatctFormObj.Seen = contactFormDto.SeenUserId;
            conatctFormObj.LastModifierUserId   = contactFormDto.SeenUserId;
            conatctFormObj.LastModificationTime = Strings.CurrentDateTime;
            _conatctFormService.Update(conatctFormObj);
            SaveChanges();
            return(contactFormDto);
        }
Exemplo n.º 6
0
        public ContactFormDto CreateConatctForm(ContactFormDto contactFormDto, int userId, int tenantId)
        {
            //if (GetContactForm(contactFormDto.InqueryId, tenantId) != null)
            //{
            //    return EditContactForm(contactFormDto, userId, tenantId);
            //}
            var conatctFormObj = Mapper.Map <Inquery>(contactFormDto);

            conatctFormObj.UserName      = contactFormDto.UserName;
            conatctFormObj.Email         = contactFormDto.Email;
            conatctFormObj.Message       = contactFormDto.Message;
            conatctFormObj.CreationTime  = Strings.CurrentDateTime;
            conatctFormObj.CreatorUserId = userId;
            _conatctFormService.Insert(conatctFormObj);
            SaveChanges();
            return(contactFormDto);
        }
        public async Task <IActionResult> CreateForm(ContactFormDto form)
        {
            var sent = await _repo.AddFormDetails(new Core.Models.ContactFormModel
            {
                SenderEmail = form.SenderEmail,
                SenderName  = form.SenderName,
                SenderPhone = form.SenderPhone,
                Message     = form.Message
            });

            if (sent)
            {
                return(Ok("Request Successful"));
            }

            return(BadRequest("Unable to process your request"));
        }
Exemplo n.º 8
0
        public Task <bool> SendMessage(ContactFormDto dto)
        {
            if (dto == null ||
                string.IsNullOrWhiteSpace(dto.Name) ||
                string.IsNullOrWhiteSpace(dto.Subject) ||
                string.IsNullOrWhiteSpace(dto.Email) ||
                string.IsNullOrWhiteSpace(dto.Message))
            {
                throw new ArgumentException("MessageService: the argument or a property thereof was null.");
            }

            var mimeMessage = new MimeMessage();

            mimeMessage.From.Add(new MailboxAddress(
                                     "Contact Form",
                                     "*****@*****.**"));

            mimeMessage.To.Add(new MailboxAddress(
                                   "Webmaster",
                                   _configuration["ContactEmail"]));

            mimeMessage.Subject = dto.Subject;

            mimeMessage.Body = new TextPart("html")
            {
                Text = FormatMessageBody(dto.Name, dto.Email, dto.Subject, dto.Message)
            };

            using (var client = new SmtpClient())
            {
                client.Connect("smtp.gmail.com", 587, false);

                client.Authenticate(
                    _configuration["ContactEmail"],
                    _configuration["ContactEmailPassword"]);

                client.Send(mimeMessage);

                client.Disconnect(true);
            }

            return(Task.FromResult(true));
        }
Exemplo n.º 9
0
        public ContactDto Add(int customerId, ContactFormDto contactDto)
        {
            var customer = GetCustomerById(customerId);

            if (customer == null)
            {
                return(null);
            }

            var contactType = _unitOfWork.ContactTypes.GetById(contactDto.ContactTypeId);

            if (contactType == null || !contactType.Validate(contactDto.Name))
            {
                return(null);
            }

            var contact = _mapper.Map <Contact>(contactDto);

            customer.AddContact(contact);

            _unitOfWork.Complete();

            return(_mapper.Map <ContactDto>(contact));
        }
Exemplo n.º 10
0
        public async Task <IActionResult> SaveContact(ContactFormDto contactFormDto)
        {
            var createdForm = await _repo.SaveContactForm(contactFormDto);

            return(StatusCode(201));
        }