public async Task <bool> CreateAsync(FuneralHome home) { _dbContext.FuneralHomes.Add(home); var result = await _dbContext.SaveChangesAsync(); return(result == 1); }
public async Task <IActionResult> PutFuneralHome(int id, FuneralHome funeralHome) { if (id != funeralHome.FuneralHomeId) { return(BadRequest()); } _context.Entry(funeralHome).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FuneralHomeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public ActionResult Settings(int?id) { if (id == null) { return(View("NotFound")); } FuneralHome home = db.FuneralHomes.Find(id); FuneralHomeSettingViewModel svm = new FuneralHomeSettingViewModel { FuneralHomeId = home.Id, Address1 = home.Address1, Address2 = home.Address2, City = home.City, Email = home.Email, LogoPath = home.Setting.LogoPath, SlatePath = home.Setting.SlatePath, Name = home.Name, State = home.State, WebsiteProvider = home.Setting.WebsiteProvider, ZipCode = home.ZipCode, FuneralHomeNumber = home.FuneralHomeNumber, PrimaryContact = home.PrimaryContact, PrimaryContactEmail = home.PrimaryContactEmail, PrimaryContactPhoneNumber = home.PrimaryContactPhoneNumber, SearchEngineFriendlyPDF = home.Setting.SEOFriendlyPDF, NewTabPdf = home.Setting.NewTabPdf, DisplayTutorials = home.Setting.DisplayTutorial, WhiteLabel = home.Setting.WhiteLabel, SelectedAzureVM = home.Setting.AzureVMSize, AzureVMSize = VMSizeDictionary.GetAzureVMSize(), DVDForSale = home.Setting.DVDForSale }; return(View(svm)); }
public async Task <ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = await UserManager.FindAsync(model.UserName, model.Password); if (user != null) { await SignInAsync(user, model.RememberMe); this.Session.Add("UserId", user.Id.ToString()); string userId = user.Id.ToString(); FuneralHome home = db.FuneralHomes.Where(u => u.UserId == userId).FirstOrDefault(); if (home != null) { home.LastLogin = DateTime.Now; db.Entry(home).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); } return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("", "Invalid username or password."); } } ViewBag.login = true; // If we got this far, something failed, redisplay form return(View(model)); }
public bool Authorize(FuneralHome home) { if (User.IsInRole("Admin")) { return(true); } if (User.IsInRole("FuneralHomeOwner")) { if (home.Owner != null) { if (User.Identity.GetUserId() == home.Owner.UserId) { return(true); } else { return(false); } } } string UserId = User.Identity.GetUserId(); if (home.UserId == UserId) { return(true); } else { return(false); } }
// GET: FuneralHomes/Create public IActionResult Create() { var fh = new FuneralHome(); fh.ParentFuneralHomes = _context.ParentFuneralHomes.ToList(); ///////////////////////////////////////////////////////////// List <Plant> lstPlants = _context.Plants.ToList(); fh.Plants.Add(new Plant() { PlantName = "-Select-", PlantId = 0 }); foreach (var item in lstPlants) { fh.Plants.Add(new Plant() { PlantName = item.PlantName, PlantId = item.PlantId }); } return(View(fh)); }
//FuneralHomeId public ActionResult WelcomeAboard(int?id, string authcode) { if (id == null) { return(View("NotFound")); } FuneralHome home = db.FuneralHomes.Find(id); if (home == null) { return(View("NotFound")); } string path = ConfigurationManager.AppSettings["portalPath"]; ViewBag.PortalPath = path; if (home.TempAccessToken != null) { ViewBag.code = Url.Action("ResetPassword", "Account", new { code = authcode, userName = home.UserName }, protocol: Request.Url.Scheme); } else { ViewBag.code = path; } return(View(home)); }
// GET: FuneralHomes/Edit/5 public ActionResult Edit(int?id) { if (!User.IsInRole("Admin")) { if (!User.IsInRole("FuneralHomeOwner")) { return(View("NotFound")); } } if (id == null) { return(View("NotFound")); } FuneralHome funeralHome = db.FuneralHomes.Find(id); if (funeralHome == null) { return(HttpNotFound()); } List <Owner> owners = new List <Owner>(); owners = db.Owners.Where(h => h.Id != null).ToList(); ViewBag.OwnerList = owners; return(View(funeralHome)); }
public static void sendWelcomeEmail(FuneralHome home) { string templatepath = ConfigurationManager.AppSettings["portalPath"] + "/Email/WelcomeAboard/" + home.Id + "?authcode=" + home.TempAccessToken; HtmlDocument page = new HtmlWeb().Load(templatepath); string sgUsername = ConfigurationManager.AppSettings["sendGridUsername"]; string sgPassword = ConfigurationManager.AppSettings["sendGridPassword"]; var myMessage = new SendGridMessage(); myMessage.AddTo(home.Email); myMessage.From = new MailAddress("*****@*****.**"); myMessage.Subject = "Welcome to Midwest Streams"; string html = page.DocumentNode.OuterHtml; myMessage.Html = html; /* SEND THE MESSAGE * ===================================================*/ var credentials = new NetworkCredential(sgUsername, sgPassword); // Create a Web transport for sending email. var transportWeb = new Web(credentials); // Send the email. SendAsync(myMessage); }
private void initParentList(FuneralHome fh) { ParentFuneralHome pfh = new ParentFuneralHome(); pfh.ParentFuneralhomeName = ""; fh.ParentFuneralHomes = new List <ParentFuneralHome>(); fh.ParentFuneralHomes.Add(pfh); _context.ParentFuneralHomes.Add(pfh); }
public FileResult getLogo(int?id) { FuneralHome home = db.FuneralHomes.Where(u => u.Id == id).FirstOrDefault(); string logopath = home.Setting.LogoPath; var FullLogoPath = ConfigurationManager.AppSettings["LogoPath"] + @"\" + logopath; return(File(FullLogoPath, "application/jpg")); }
private void addParent(FuneralHome fh) { ParentFuneralHome pfh = new ParentFuneralHome(); pfh.ParentFuneralhomeName = fh.Name; fh.ParentFuneralHomes = _context.ParentFuneralHomes.ToList(); fh.ParentFuneralHomes.Add(pfh); _context.ParentFuneralHomes.Add(pfh); }
public ActionResult SendWelcomeMessage(int?id) { if (id == null) { return(View("NotFound")); } FuneralHome home = db.FuneralHomes.Find(id); return(View(home)); }
public async Task <IActionResult> Create([Bind("FuneralHomeId,ParentFuneralHomeId,PlantId,Name,Address,Address2,City,State,ZipCode,County,Email,Website,Phone1,Phone2,Phone3,PhoneType1,PhoneType2,PhoneType3,IsParent,ParentName,PlantName")] FuneralHome funeralHome) { if (ModelState.IsValid) { // If no parent funeralhomes exist... if (_context.ParentFuneralHomes.Count() == 0) { // if this funeralhome is a parent funeral home... if (funeralHome.IsParent) { // 1) initialize a list of funeral homes. initParentList(funeralHome); // 2) add to list of funeral homes. addParent(funeralHome); } else { // if this funeralhome is a parent funeral home... initParentList(funeralHome); } } else { if (funeralHome.IsParent) { // add to list of funeral homes. addParent(funeralHome); } } if (funeralHome.ParentFuneralHomeId != null) { var pfh = new ParentFuneralHome(); pfh = await _context.ParentFuneralHomes.FindAsync(funeralHome.ParentFuneralHomeId); funeralHome.ParentName = pfh.ParentFuneralhomeName; } if (funeralHome.PlantId != 0) { Plant plt = await _context.Plants.FindAsync(funeralHome.PlantId); funeralHome.PlantName = plt.PlantName; } _context.FuneralHomes.Add(funeralHome); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } // ViewData["PlantId"] = new SelectList(_context.Plants, "PlantId", "PlantId", funeralHome.PlantId); return(View(funeralHome)); }
public ActionResult ToggleTutorial(bool displayTutorial) { var userId = User.Identity.GetUserId(); FuneralHome home = db.FuneralHomes.Where(h => h.UserId == userId).FirstOrDefault(); if (home.Setting != null) { home.Setting.DisplayTutorial = displayTutorial; db.Entry(home).State = EntityState.Modified; db.SaveChanges(); } return(Json(new { foo = "bar", baz = "Blech" })); }
/* ------------------ End Create Home ------------------ */ public void SendWelcomeEmail(int id) { var provider = new DpapiDataProtectionProvider("VideoManager"); UserManager.UserTokenProvider = new DataProtectorTokenProvider <ApplicationUser>( provider.Create("EmailConfirmation")); FuneralHome home = db.FuneralHomes.Find(id); var code = UserManager.GeneratePasswordResetToken(home.UserId); home.TempAccessToken = code; db.Entry(home).State = EntityState.Modified; db.SaveChanges(); Email.sendWelcomeEmail(home); }
public ActionResult Edit(FuneralHome funeralHome) { if (ModelState.IsValid) { db.Entry(funeralHome).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } List <Owner> owners = new List <Owner>(); owners = db.Owners.Where(h => h.Id != null).ToList(); ViewBag.OwnerList = owners; return(View(funeralHome)); }
public ActionResult Contact() { ViewBag.Message = "Your contact page."; var userId = User.Identity.GetUserId(); FuneralHome home = db.FuneralHomes.Where(f => f.UserId == userId).FirstOrDefault(); if (home != null) { if (home.Setting != null) { ViewBag.DisplayTutorialCheckbox = home.Setting.DisplayTutorial; } } return(View()); }
public ActionResult DeleteConfirmed(int id) { CRMFuneralHome home = db.CRMFuneralHome.Where(h => h.FuneralHomeId == id).FirstOrDefault(); if (home != null) { home.FuneralHomeId = null; home.FuneralHome = null; db.Entry(home).State = EntityState.Modified; db.SaveChanges(); } FuneralHome funeralHome = db.FuneralHomes.Find(id); db.FuneralHomes.Remove(funeralHome); db.SaveChanges(); return(RedirectToAction("Index")); }
public async Task <bool> DeleteAsync(FuneralHome home) { try { _dbContext.FuneralHomes.Remove(home); await _dbContext.SaveChangesAsync(); _logger.LogInformation("Funeral Home successfully deleted."); return(true); } catch (DbUpdateException e) { _logger.LogError(e.Message); throw; } }
public ActionResult Create(FuneralHomeCreateViewModel funeralHomeView) { FuneralHome funeralHome = new FuneralHome() { Address1 = funeralHomeView.Address1, Address2 = funeralHomeView.Address2, City = funeralHomeView.City, State = funeralHomeView.State, ZipCode = funeralHomeView.ZipCode, Email = funeralHomeView.Email, UserName = funeralHomeView.UserName, OwnerId = funeralHomeView.OwnerId, PaymentStatus = funeralHomeView.PaymentStatus, Name = funeralHomeView.Name, FuneralHomeNumber = funeralHomeView.FuneralHomeNumber, PrimaryContact = funeralHomeView.PrimaryContact, PrimaryContactEmail = funeralHomeView.PrimaryContactEmail, PrimaryContactPhoneNumber = funeralHomeView.PrimaryContactPhoneNumber, DevHome = funeralHomeView.DevHome, }; if (db.Users.Where(u => u.UserName == funeralHomeView.UserName).Count() > 1) { ViewBag.ErrorText = "Login name already in use"; return(View(funeralHomeView)); } if (ModelState.IsValid) { FuneralHomeHelper fhh = new FuneralHomeHelper(); var fhresult = fhh.CreateFuneralHome(funeralHome, funeralHomeView.UserName, funeralHomeView.WebsiteProvider); if (fhresult.Success == true) { return(RedirectToAction("Index")); } else { ViewBag.ErrorText = fhresult.UserErrors; } } List <Owner> owners = new List <Owner>(); owners = db.Owners.Where(h => h.Id != null).ToList(); ViewBag.OwnerList = owners; return(View(funeralHomeView)); }
public async Task <bool> UpdateAsync(FuneralHome home) { _dbContext.Attach(home).State = EntityState.Modified; try { await _dbContext.SaveChangesAsync(); _logger.LogInformation("Funeral Home successfully updated."); return(true); } catch (DbUpdateConcurrencyException e) { _logger.LogError(e.Message); throw; } }
//DONT USE THIS IF YOU NEED TO ALLOW LARGE FILES UPLOADS //Credit to i-e-b and his ASP.Net uploader for the bulk of the upload helper methods - https://github.com/i-e-b/jQueryFileUpload.Net private void UploadWholeFile(HttpRequestBase request, List <ViewDataUploadFilesResult> statuses, string userId) { for (int i = 0; i < request.Files.Count; i++) { FuneralHome home = db.FuneralHomes.Where(u => u.UserId == userId).FirstOrDefault(); // setup file information /*test variable*/ string testPath = Path.Combine(home.Id + "_" + home.Name + ".*"); testPath = testPath.Replace(" ", ""); var file = request.Files[i]; var fullPath = Path.Combine(ConfigurationManager.AppSettings["LogoPath"], userId + Path.GetFileName(file.FileName)); var filename = home.Id + "_" + home.Name + Path.GetExtension(file.FileName); filename = filename.Replace(" ", ""); fullPath = Path.Combine(ConfigurationManager.AppSettings["LogoPath"], filename); //check to see if the file exist string logoFolder = ConfigurationManager.AppSettings["LogoPath"]; string[] fileList = Directory.GetFiles(logoFolder, testPath); int filenum = fileList.Length; if (fileList.Length > 0) { foreach (string f in fileList) { System.IO.File.Delete(f); } } file.SaveAs(fullPath); home.Setting.LogoPath = filename; db.SaveChanges(); statuses.Add(new ViewDataUploadFilesResult() { Name = file.FileName, Size = file.ContentLength, Type = file.ContentType, Url = "/Home/Download/" + file.FileName, DeleteUrl = "/Home/Delete/" + file.FileName, ThumbnailUrl = @"data:image/png;base64," + Convert.ToBase64String(System.IO.File.ReadAllBytes(fullPath)), DeleteType = "GET", }); } }
public ActionResult Settings(FuneralHomeSettingViewModel svm) { if (ModelState.IsValid) { FuneralHome dbHome = db.FuneralHomes.Find(svm.FuneralHomeId); dbHome.Address1 = svm.Address1; dbHome.Address2 = svm.Address2; dbHome.City = svm.City; dbHome.Email = svm.Email; dbHome.Name = svm.Name; dbHome.Setting.LogoPath = svm.LogoPath; dbHome.Setting.SlatePath = svm.SlatePath; dbHome.Setting.WebsiteProvider = svm.WebsiteProvider; dbHome.Setting.DisplayTutorial = svm.DisplayTutorials; dbHome.Setting.NewTabPdf = svm.NewTabPdf; dbHome.FuneralHomeNumber = svm.FuneralHomeNumber; dbHome.PrimaryContact = svm.PrimaryContact; dbHome.PrimaryContactPhoneNumber = svm.PrimaryContactPhoneNumber; dbHome.PrimaryContactEmail = svm.PrimaryContactEmail; dbHome.Setting.SEOFriendlyPDF = svm.SearchEngineFriendlyPDF; dbHome.Setting.WhiteLabel = svm.WhiteLabel; if (svm.AzureVMSize != null) { dbHome.Setting.AzureVMSize = svm.SelectedAzureVM; } dbHome.Setting.DVDForSale = svm.DVDForSale; db.SaveChanges(); } var errors = ModelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .ToList(); if (User.IsInRole("Admin")) { return(RedirectToAction("Index")); } else { return(RedirectToAction("Index", "Services")); } }
public ActionResult SetPassword(int?id) { if (id == null) { return(View("NotFound")); } //Sensitive page don't let anyone access it bool hasAccess = false; FuneralHome home = db.FuneralHomes.Find(id); if (home == null) { return(View("NotFound")); } if (home.UserId == null) { return(View("Error")); } if (home.UserId == User.Identity.GetUserId()) { hasAccess = true; } if (User.IsInRole("Admin")) { hasAccess = true; } if (hasAccess == false) { return(View("NotFound")); } ViewBag.StatusMessage = ""; ViewBag.FuneralHomeName = home.Name; ViewBag.ReturnUrl = Url.Action("SetPassword"); ManageUserViewModel model = new ManageUserViewModel(); model.UserId = home.UserId; model.FuneralHomeId = id; return(View(model)); }
// GET: FuneralHomes/Delete/5 public ActionResult Delete(int?id) { if (!User.IsInRole("Admin")) { if (!User.IsInRole("FuneralHomeOwner")) { return(View("NotFound")); } } if (id == null) { return(View("NotFound")); } FuneralHome funeralHome = db.FuneralHomes.Find(id); if (funeralHome == null) { return(View("NotFound")); } return(View(funeralHome)); }
public ActionResult Manage(int?id) { if (id == null) { if (User.IsInRole("Admin")) { ViewBag.FuneralHomeId = new SelectList(db.FuneralHomes, "Id", "Name"); Service servy = new Service { ServiceDate = DateTime.Now, DeathDay = DateTime.Now.AddDays(-3), Birthday = DateTime.Now.AddYears(-80) }; return(View(servy)); } var userId = User.Identity.GetUserId(); FuneralHome home = db.FuneralHomes.Where(f => f.UserId == userId).FirstOrDefault(); Service service = new Service { FuneralHomeId = home.Id, ServiceDate = DateTime.Now, DeathDay = DateTime.Now.AddDays(-3), Birthday = DateTime.Now.AddYears(-80) }; return(View(service)); } Service prevService = db.Services.Find(id); if (prevService == null || !Authorize(prevService.FuneralHome)) { return(View("NotFound")); } return(View(prevService)); }
public ActionResult HomeSettings(string id) { FuneralHome home = db.FuneralHomes.Where(f => f.UserId == id).FirstOrDefault(); if (home != null) { FuneralHomeSettingViewModel svm = new FuneralHomeSettingViewModel { FuneralHomeId = home.Id, Address1 = home.Address1, Address2 = home.Address2, City = home.City, Email = home.Email, LogoPath = home.Setting.LogoPath, SlatePath = home.Setting.SlatePath, Name = home.Name, State = home.State, WebsiteProvider = home.Setting.WebsiteProvider, ZipCode = home.ZipCode, DisplayTutorials = home.Setting.DisplayTutorial, NewTabPdf = home.Setting.NewTabPdf, FuneralHomeNumber = home.FuneralHomeNumber, PrimaryContact = home.PrimaryContact, PrimaryContactEmail = home.PrimaryContactEmail, PrimaryContactPhoneNumber = home.PrimaryContactPhoneNumber, SearchEngineFriendlyPDF = home.Setting.SEOFriendlyPDF, WhiteLabel = home.Setting.WhiteLabel, SelectedAzureVM = home.Setting.AzureVMSize, AzureVMSize = VMSizeDictionary.GetAzureVMSize(), DVDForSale = home.Setting.DVDForSale }; return(View("Settings", svm)); } else { return(View("NotFound")); } }
public ActionResult ViewedAnnouncment(int?announcmentId) { var userId = User.Identity.GetUserId(); FuneralHome home = db.FuneralHomes.Where(h => h.UserId == userId).FirstOrDefault(); if (home.Setting != null) { Announcment a = db.Announcments.Find(announcmentId); if (a != null) { List <Announcment> announcments = new List <Announcment>(); if (home.AnnouncmentsViewed != null) { announcments = home.AnnouncmentsViewed; } announcments.Add(a); home.AnnouncmentsViewed = announcments; db.Entry(home).State = EntityState.Modified; db.SaveChanges(); return(Json(new { success = "true" })); } } return(Json(new { success = "false" })); }
public async Task <IActionResult> Edit(int id, [Bind("FuneralHomeId,ParentFuneralHomeId,PlantId," + "Name,Address,Address2,City,State,ZipCode,County,Email,Website,Phone1,Phone2,Phone3," + "PhoneType1,PhoneType2,PhoneType3,IsParent,ParentName,PlantName")] FuneralHome funeralHome) { //if (id != funeralHome.FuneralHomeId) if (id == 0) { return(NotFound()); } if (ModelState.IsValid) { if (_context.ParentFuneralHomes.Count() > 1) { ParentFuneralHome parentFuneralHome = await _context.ParentFuneralHomes.FindAsync(funeralHome.ParentFuneralHomeId); if (funeralHome.IsParent && parentFuneralHome == null) { initParentList(funeralHome); addParent(funeralHome); } else { initParentList(funeralHome); } funeralHome.ParentName = parentFuneralHome.ParentFuneralhomeName; } else { ParentFuneralHome parentFuneralHome = await _context.ParentFuneralHomes.FindAsync(funeralHome.ParentFuneralHomeId); if (funeralHome.IsParent && parentFuneralHome == null) { addParent(funeralHome); } if (parentFuneralHome != null) { funeralHome.ParentName = parentFuneralHome.ParentFuneralhomeName; } } if (funeralHome.PlantId != 0) { Plant plt = await _context.Plants.FindAsync(funeralHome.PlantId); funeralHome.PlantName = plt.PlantName; } try { _context.Update(funeralHome); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FuneralHomeExists(funeralHome.FuneralHomeId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(funeralHome)); }