public void SendEmailToUser(ContactAdModel model)
        {
            String subject = String.Format("{0} - Notification : \"{1}\"", _appSettingsProvider.WebsiteName, model.AdTitle);
            String body    = String.Format("Bonjour,"
                                           + "un utilisateur du site {0}, {1}, vous envoie le message suivant. Vous pouvez lui repondre directement à partir de cet email ou par telephone: {2}.\n\n"
                                           + "---------------------------------------------------------------\n\n"
                                           + model.EmailBody + "\n\n"
                                           + "---------------------------------------------------------------\n\n"
                                           + "http://www.{0}/Post/Details/{3}", _appSettingsProvider.WebsiteAddress, model.Name, (String.IsNullOrEmpty(model.Telephone)) ? "non communiqué" : model.Telephone, model.AdId);

            _emailService.SendEmail(subject, body, model.EmailTo, model.Email);
        }
Beispiel #2
0
        public PartialViewResult Contact(ContactAdModel model)
        {
            //ContactAdModel result = model;
            IDictionary <string, string> errors = _adConsistencyServices.GetDataConsistencyErrors(model);

            foreach (string key in errors.Keys)
            {
                ModelState.AddModelError(key, errors[key]);
            }
            if (ModelState.IsValid)
            {
                model = _adContactServices.ContactAd(model);
            }
            return(PartialView("_Contact", model));
        }
Beispiel #3
0
        public Dictionary <string, string> GetDataConsistencyErrors(ContactAdModel model)
        {
            Dictionary <string, string> errors = new Dictionary <string, string>();

            if (String.IsNullOrEmpty(model.Name))
            {
                errors.Add("Name", "Veuillez saisir votre nom.");
            }
            if (String.IsNullOrEmpty(model.Email))
            {
                errors.Add("Email", "Veuillez saisir votre adresse email.");
            }
            else
            if (!String.IsNullOrEmpty(model.Email) && !_emailRegex.IsMatch(model.Email))
            {
                errors.Add("Email", "Email invalide.");
            }
            if (String.IsNullOrEmpty(model.EmailBody))
            {
                errors.Add("EmailBody", "Veuillez saisir un texte.");
            }
            return(errors);
        }
        public ContactAdModel ContactAd(ContactAdModel model)
        {
            //ContactAdModel result = new ContactAdModel(model.AdId);
            BaseAd ad = _adRepository.GetAdById <BaseAd>(model.AdId);

            if (ad == null || ad.IsDeleted)
            {
                model.InfoMessage  = "Cette annonce n'existe pas ou plus.";
                model.CanContactAd = false;
                return(model);
            }
            //Should never happened, and should be logged for investigation if it does
            if (ad.CreatedBy == null)
            {
                model.InfoMessage  = "Impossible de contacter l'annonceur.";
                model.CanContactAd = false;
                return(model);
            }
            User user = _repository.Get <User>(ad.CreatedBy.Id);

            if (user == null)
            {
                model.InfoMessage  = "Impossible de contacter l'annonceur.";
                model.CanContactAd = false;
                return(model);
            }
            model.EmailTo = user.Email;
            SendEmailToUser(model);
            if (model.CopySender)
            {
                model.EmailTo = model.Email;
                SendEmailToUser(model);
            }
            model.CanContactAd = true;
            model.InfoMessage  = "Votre message a été envoyé !";
            return(model);
        }