public ActionResult CreateEntry(CreateEducationViewModel model, HttpPostedFileBase File) { var user = UserManager.FindById(User.Identity.GetUserId()); var fileString = FileUpload(File); Ctx.EducationBlogs.Add(new EducationBlogModel { AttachedFile = fileString, Time = DateTime.Now, Title = model.Title, Content = model.Content, CreatorId = user.Id }); Ctx.SaveChanges(); //var EmailRecipients = (from U in Ctx.Users // where U.Notifications == "Email" // || U.Notifications == "EmailSms" // where U.Id != user.Id // select U).ToList(); //string subject = "Nytt inlägg från " + user.FirstName + "."; //string emailText = "Inlägg med rubrik: " + model.Title + " finns nu att läsa."; //foreach (var appUser in EmailRecipients) //{ // var emailHelper = new EmailHelper("*****@*****.**", "Kakan1210", appUser.Email); // emailHelper.SendEMail(appUser.Email, subject, emailText); //} return(RedirectToAction("Index")); }
public ActionResult EditEducation(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } EntryEducation old = db.EntryEducation.Find(id); EntryEducation entryEducation = new EntryEducation(); entryEducation.Id = old.Id; entryEducation.Heading = old.Heading; entryEducation.text = old.text; entryEducation.Date = DateTime.Now; entryEducation.Filename = old.Filename; entryEducation.ContentType = old.ContentType; entryEducation.File = old.File; entryEducation.Author = old.Author; if (entryEducation == null) { return(HttpNotFound()); } var model = new CreateEducationViewModel(); var tags = new List <SelectListItem>(); var existingTags = new List <SelectListItem>(); tags = db.EducationTag.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.TagName }).ToList(); var tagEntries = db.EducationTagEntries.Where(x => x.EntryId == entryEducation.Id).ToList(); List <string> tagIDs = new List <string>(); foreach (var tag in tagEntries) { existingTags.Add(tags.First(x => x.Value == tag.TagId)); tags.Remove(tags.First(x => x.Value == tag.TagId)); } model.TagNameList = tags; model.ExistingTagNameList = existingTags; model.Entries = entryEducation; return(View(model)); }
public ActionResult CreateEducation() { var model = new CreateEducationViewModel(); var tags = new List <SelectListItem>(); tags = db.EducationTag.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.TagName }).ToList(); model.TagNameList = tags; return(View(model)); }
public ActionResult CreateEducation(CreateEducationViewModel model, HttpPostedFileBase picUpload) { if (Request.IsAuthenticated && ModelState.IsValid) { var user = db.Users.Find(User.Identity.GetUserId()) as ApplicationUser; EntryEducation aEntry = new EntryEducation(); if (picUpload != null && picUpload.ContentLength > 0) { aEntry.Filename = picUpload.FileName; aEntry.ContentType = picUpload.ContentType; using (var reader = new BinaryReader(picUpload.InputStream)) { aEntry.File = reader.ReadBytes(picUpload.ContentLength); } } aEntry.Heading = model.Entries.Heading; aEntry.text = model.Entries.text; aEntry.Date = DateTime.Now; aEntry.Author = user; user.EducationEntries.Add(aEntry); db.EntryEducation.Add(aEntry); db.SaveChanges(); if (model.SelectedTagIds != null) { foreach (var item in model.SelectedTagIds) { var selectedTag = new EducationTagEntries(); selectedTag.EntryId = db.EntryEducation.Max(x => x.Id); selectedTag.TagId = db.EducationTag.Where(x => x.TagName == item).SingleOrDefault().Id.ToString(); db.EducationTagEntries.Add(selectedTag); } } db.SaveChanges(); return(RedirectToAction("Education", "EntryInformative", new { id = user.Id })); } var tags = new List <SelectListItem>(); tags = db.EducationTag.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.TagName }).ToList(); model.TagNameList = tags; return(View(model)); }
public ActionResult EditEducation(CreateEducationViewModel model, HttpPostedFileBase picUpload) //Av någon anledning följer inte tagg-listan med... { EntryEducation entryToUpdate = new EntryEducation(); if (ModelState.IsValid) { entryToUpdate = db.EntryEducation.Find(model.Entries.Id); entryToUpdate.text = model.Entries.text; entryToUpdate.Heading = model.Entries.Heading; entryToUpdate.Date = model.Entries.Date; if (picUpload != null && picUpload.ContentLength > 0) { entryToUpdate.Filename = picUpload.FileName; entryToUpdate.ContentType = picUpload.ContentType; using (var reader = new BinaryReader(picUpload.InputStream)) { entryToUpdate.File = reader.ReadBytes(picUpload.ContentLength); } } db.SaveChanges(); var entryTags = db.EducationTagEntries.Where(x => x.EntryId == model.Entries.Id).ToList(); if (entryTags != null) { db.EducationTagEntries.RemoveRange(entryTags); db.SaveChanges(); } if (model.SelectedTagIds != null) { foreach (var item in model.SelectedTagIds) { var selectedTag = new EducationTagEntries(); selectedTag.EntryId = db.EntryEducation.Max(x => x.Id); try { selectedTag.TagId = db.EducationTag.SingleOrDefault(x => x.TagName == item).Id.ToString(); } catch { selectedTag.TagId = item; } db.EducationTagEntries.Add(selectedTag); } } db.SaveChanges(); return(RedirectToAction("Education")); } var tags = new List <SelectListItem>(); tags = db.EducationTag.Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.TagName }).ToList(); model.TagNameList = tags; model.ExistingTagNameList = new List <SelectListItem>(); return(View(model)); }