public async void AddContactPostSucceedsOnAdd()
        {
            var mailer = new Mock <IEmailSender>();
            // Setup repo mock that accepts one Id but not another
            var good = new ContactLog();
            var repo = new Mock <ILogRepository>();

            repo.Setup(r => r.AddAsync(good)).Returns(Task.FromResult(true));
            repo.Setup(r => r.AddAsync(null)).Returns(Task.FromResult(false));

            // Good data test
            var ctrl   = new LogListsController(repo.Object, mailer.Object);
            var result = await ctrl.AddContact(good);

            Assert.IsType <JsonResult>(result);
            dynamic model = result.Value;

            Assert.True(model.success);

            // Bad data test
            result = await ctrl.AddContact(null);

            Assert.IsType <JsonResult>(result);
            model = result.Value;
            Assert.False(model.success);
        }
Exemple #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            if (IsValid)
            {
                using (var db = new ContactDatabase())
                {
                    var log = new ContactLog()
                    {
                        Name     = txtName.Text,
                        Email    = txtEmail.Text,
                        Subject  = txtSubject.Text,
                        Message  = txtMessage.Text,
                        DateSent = DateTime.Now
                    };

                    db.ContactLogs.Add(log);
                    db.SaveChanges();

                    pnlFormFields.Visible     = false;
                    pnlSuccessMessage.Visible = true;
                }
            }
            else
            {
            }
        }
Exemple #3
0
        public ActionResult Log(ContactLogViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(viewModel));
            }
            else
            {
                if (viewModel.ContactLogId > 0)
                {
                    ContactLog foundLog = _db.ContactLogs.Find(viewModel.ContactLogId);
                    foundLog.Copy(viewModel);
                }
                else
                {
                    var newLog = new ContactLog(viewModel);
                    this._db.ContactLogs.Add(newLog);
                }

                this._db.SaveChanges();

                Response.Redirect("~/Mentor");
            }

            return(this.View());
        }
Exemple #4
0
        public async Task <EmailTemplate> SaveContactLog(ContactLog model)
        {
            _contactLogRep.Insert(model);

            var emailTemp = await _emailTemplateRep.Where(e => e.EmailType == 1).FirstOrDefaultAsync();

            return(emailTemp);
        }
        public ActionResult Contact(ContactViewModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var db = new BluSignalsEntities();

                    var conact = new ContactLog()
                    {
                        Name        = model.Name,
                        Email       = model.Email,
                        Message     = model.Message,
                        Subject     = model.Subject,
                        CreatedDate = DateTime.UtcNow
                    };


                    var emailTemp = db.EmailTemplates.Where(e => e.EmailType == 1).FirstOrDefault();

                    var EB = new StringBuilder(emailTemp.EmailBody);

                    EB.Replace("@Name", conact.Name);
                    EB.Replace("@Email", conact.Email);
                    EB.Replace("@Subject", conact.Subject);
                    EB.Replace("@Query", conact.Message);
                    MailHelper.SendMailMessage(CommonConfig.AdminEmailID, "", "", emailTemp.EmailSubject + "-" + conact.Subject, EB.ToString(), true);

                    db.ContactLogs.Add(conact);
                    db.SaveChanges();



                    var model2 = new ContactViewModel();
                    ModelState.Clear();
                    model2.IsSuccess = 2;
                    //model2.Name = string.Empty;
                    //model2.Email = string.Empty;
                    //model2.Message = string.Empty;
                    //model2.Subject = string.Empty;



                    return(PartialView("_ContactLog", model2));
                }
                else
                {
                    model.IsSuccess = 1;
                }
            }
            catch (Exception)
            {
                throw;
            }
            return(PartialView("_ContactLog", model));
        }
        public async Task <JsonResult> AddContact([FromBody] ContactLog log)
        {
            if (ModelState.IsValid)
            {
                var added = await _logRepository.AddAsync(log);

                if (added)
                {
                    return(Json(new { success = true, data = log }));
                }
            }
            return(Json(new { success = false }));
        }
        public async Task <JsonResult> EditContact(Guid Id, [FromBody] ContactLog log)
        {
            if (ModelState.IsValid)
            {
                log.Id = Id;
                var success = await _logRepository.UpdateAsync(log);

                if (success)
                {
                    return(Json(new { success = true }));
                }
            }
            return(Json(new { success = false }));
        }
 /// <summary>
 /// Take data from 'ConctactLogViewModel' and save to Db table 'contactLog', if model is not valid return false.
 /// </summary>
 /// <param name="model">'ContactLogViewModel'</param>
 /// <returns>bool</returns>
 public bool addContactLog(ConctactLogViewModel model)
 {
     if (model._contactName != null || model._contactEmail != null || model._contactEmail != null) // FIXME::?
     {
         ContactLog contactLog = new ContactLog
         {
             _contactName    = model._contactName,
             _contactEmail   = model._contactEmail,
             _ContactMessage = model._contactMessage
         };
         _db._contacts.Add(contactLog);
         _db.SaveChanges();
         return(true);
     }
     return(false);
 }
        public async void EmailReportGeneratesEntryPerLog()
        {
            var mailer = new Mock <IEmailSender>();

            mailer.Setup(r => r.SendEmailAsync("", It.IsAny <string>(),
                                               It.IsRegex(".*conlog.*actlog.*",
                                                          RegexOptions.Multiline & RegexOptions.IgnoreCase)))
            .Returns(Task.FromResult(false));
            // Setup repo mock that succeeds deleting one id
            var con = new ContactLog()
            {
                Id          = new Guid(),
                LogDate     = DateTime.Now,
                Description = "Conlog"
            };
            var act = new ActivityLog()
            {
                Id          = new Guid(),
                LogDate     = DateTime.Now,
                Description = "Actlog"
            };
            var repo = new Mock <ILogRepository>();

            repo.Setup(r => r.GetLogAsync(con.Id))
            .Returns(Task.FromResult(con as BaseLog));
            repo.Setup(r => r.GetLogAsync(act.Id))
            .Returns(Task.FromResult(act as BaseLog));

            var ctrl   = new LogListsController(repo.Object, mailer.Object);
            var result = await ctrl.EmailReport(new List <Guid> {
                con.Id, act.Id
            });

            Assert.IsType <JsonResult>(result);
            dynamic model = result.Value;

            Assert.True(model.success);

            // Bad guid test (this never hits the repo)
            result = await ctrl.Delete("vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv");

            Assert.IsType <JsonResult>(result);
            model = result.Value;
            Assert.False(model.success);
        }
Exemple #10
0
        public async Task <bool> AddContanctLogAsync(string message)
        {
            var toBeSendedMessages = await _context.Contacts
                                     .Where(contact => !contact.ContactLogs.Any(contactLog => contactLog.Contact == contact))
                                     .Include(c => c.ContactLogs)
                                     .Take(TakeNumber)
                                     .ToListAsync();

            if (toBeSendedMessages.Count == ZeroValue)
            {
                return(false);
            }

            toBeSendedMessages.ForEach(contact => contact.ContactLogs.Add(ContactLog.New(message)));

            await _context.SaveChangesAsync();

            return(true);
        }
        public async void EditContactPostSucceedsOnUpdate()
        {
            var mailer = new Mock <IEmailSender>();
            // Setup repo mock that accepts one Id but not another
            var good = new ContactLog();

            good.Id = new Guid();
            var bad = new ContactLog();

            bad.Id = new Guid();
            var repo = new Mock <ILogRepository>();

            repo.Setup(r => r.UpdateAsync(good)).Returns(Task.FromResult(true));
            repo.Setup(r => r.UpdateAsync(bad)).Returns(Task.FromResult(false));

            // Good guid test
            var ctrl   = new LogListsController(repo.Object, mailer.Object);
            var result = await ctrl.EditContact(good.Id, good);

            Assert.IsType <JsonResult>(result);
            dynamic model = result.Value;

            Assert.True(model.success);

            // Bad guid test
            result = await ctrl.EditContact(bad.Id, bad);

            Assert.IsType <JsonResult>(result);
            model = result.Value;
            Assert.False(model.success);

            // No guid test
            result = await ctrl.EditContact(Guid.Empty, bad);

            Assert.IsType <JsonResult>(result);
            model = result.Value;
            Assert.False(model.success);
        }
Exemple #12
0
 public string RenderContact(ContactLog log)
 {
     return($@"<h2>Contact log</h2>
               <dl>
                   <dt>Date:</dt>
                   <dd>{log.LogDate.ToShortDateString()}</dd>
                   <dt>Employer:</dt>
                   <dd>{log.Employer}</dd>
                   <dt>Contact:</dt>
                   <dd>{log.Contact}</dd>
                   <dt>Contacted type:</dt>
                   <dd>{typeof(ContactType).GetEnumName(log.ContactType)}</dd>
                   <dt>Means:</dt>
                   <dd>{typeof(ContactMeans).GetEnumName(log.ContactMeans)}</dd>
                   <dt>Address:</dt>
                   <dd>{log.Address}</dd>
                   <dt>City:</dt>
                   <dd>{log.City}</dd>
                   <dt>State:</dt>
                   <dd>{log.State}</dd>
                   <dt>Description:</dt>
                   <dd><pre>{log.Description}</pre></dd>
               </dl><hr />");
 }