Пример #1
0
        public ActionResult DeleteConfirmed(int id)
        {
            Entries         entries = db.Entries.Find(id);
            EntryTagEntries aEntry  = db.EntryTagEntries.Find(entries.Id);

            db.EntryTagEntries.Remove(aEntry);
            db.Entries.Remove(entries);
            db.SaveChanges();
            return(RedirectToAction("IndexFormal"));
        }
Пример #2
0
        public ActionResult CreateTest(CreateEntryViewModel model, HttpPostedFileBase picUpload)
        {
            if (Request.IsAuthenticated && ModelState.IsValid)
            {
                var     user   = db.Users.Find(User.Identity.GetUserId()) as ApplicationUser;
                Entries aEntry = new Entries();

                aEntry.Author  = user;
                aEntry.text    = model.Entries.text;
                aEntry.Heading = model.Entries.Heading;
                aEntry.Date    = DateTime.Today;

                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);
                    }
                }

                user.Entries.Add(aEntry);
                db.Entries.Add(aEntry);
                db.SaveChanges();
                if (model.SelectedTagIds != null)
                {
                    foreach (var item in model.SelectedTagIds)
                    {
                        var selectedTag = new EntryTagEntries();
                        selectedTag.EntryId = db.Entries.Max(x => x.Id);
                        selectedTag.TagId   = db.EntryTags.Where(x => x.TagName == item).SingleOrDefault().Id.ToString();
                        db.EntryTagEntries.Add(selectedTag);
                    }
                }

                db.SaveChanges();

                var emails  = db.Users.Where(x => x.GetMail).Select(x => x.Email).ToList();
                var subject = user.Email + " har skrivit ett formellt inlägg.";
                var message = user.Email + " har lagt upp ett inlägg med titeln: " + model.Entries.Heading + ".";

                DataLogic.DbMethods.Methods.SendEmailInvitation(emails, message, subject);
                DataLogic.DbMethods.EmailJob.count += 1;
                return(RedirectToAction("IndexFormal", new { Id = user.Id }));
            }
            var tags = new List <SelectListItem>();

            tags = db.EntryTags.Select(x => new SelectListItem {
                Value = x.Id.ToString(), Text = x.TagName
            }).ToList();
            model.TagNameList = tags;
            return(View(model));
        }