public void AddUserModuleEmailById(Guid id, UserModuleEmails email) { var userModule = _context.UserModules.FirstOrDefault(m => m.Id.Equals(id)); if (userModule != null) { userModule.ModuleEmails.Add(email); _context.SaveChanges(); } }
public PartialViewResult SendEmail(EmailViewModel emailVM) { string logEmail = $"{{\"email\":{{\"title\":\"{emailVM.NewEmail.Title}\",\"to\":\"{emailVM.NewEmail.To}\",\"body\":\"{emailVM.NewEmail.Body}\"}}}}"; ICollection <UserModuleEmails> outgoing = new List <UserModuleEmails>(); if (String.IsNullOrEmpty(emailVM.UserModuleId)) { CookieWrapper.GuestLog += logEmail; outgoing = ParseLogEmails(CookieWrapper.GuestLog + logEmail); } else { ModuleManager.AddToLogById(new Guid(emailVM.UserModuleId), logEmail); UserModuleEmails email = new UserModuleEmails() { Body = emailVM.NewEmail.Body, Id = Guid.NewGuid(), Title = emailVM.NewEmail.Title, To = emailVM.NewEmail.To }; ModuleManager.AddUserModuleEmailById(new Guid(emailVM.UserModuleId), email); outgoing = ModuleManager.GetOutgoingEmailsByUserModuleId(new Guid(emailVM.UserModuleId)); } var incoming = ModuleManager.GetIncomingEmailsByModuleId(new Guid(emailVM.ModuleId)); ModelState.Clear(); return(PartialView("Email", new EmailViewModel() { Inbox = incoming.Select(e => Mapper.Map <ModuleEmailsViewModels>(e)).ToList(), Outbox = outgoing.Select(e => Mapper.Map <UserModuleEmailsViewModels>(e)).ToList(), UserModuleId = emailVM.UserModuleId, Username = emailVM.Username, NewEmail = new UserModuleEmailsViewModels(), ModuleId = emailVM.ModuleId })); }