コード例 #1
0
        public ActionResult Create(CheatNote cheatNote, string questionsPlainText)
        {
            try
            {
                var cheatNoteItems = ParseCheatNoteItems(questionsPlainText);

                if (cheatNoteItems != null && cheatNoteItems.Count > 0)
                {
                    foreach (var item in cheatNoteItems)
                    {
                        item.CreatedById = GetCurrentUserId();
                    }

                    cheatNote.Items = cheatNoteItems;
                }

                using (var db = new CheatNotesContext())
                {
                    cheatNote.CreatedById = GetCurrentUserId();

                    db.CheatNotes.Add(cheatNote);
                    db.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View(cheatNote);
            }
        }
コード例 #2
0
        public static IEnumerable<CheatNoteGeneratedHtml> GenerateHtmlFiles(string fileName, CheatNote cheatNote, long? partSize)
        {
            if (string.IsNullOrWhiteSpace(fileName) || cheatNote == null || cheatNote.Items == null)
            {
                return Enumerable.Empty<CheatNoteGeneratedHtml>();
            }

            var itemsTree = SplitCheatNoteItems(cheatNote.Items.Where(x => !x.DateDeleted.HasValue).OrderBy(x => x.Position), partSize);

            return itemsTree.Any() ? GenerateHtmlCollection(fileName, cheatNote.Name, itemsTree) : Enumerable.Empty<CheatNoteGeneratedHtml>();
        }
コード例 #3
0
        public ActionResult Edit(int id, CheatNote cheatNote)
        {
            try
            {
                using (var db = new CheatNotesContext())
                {
                    var instance = db.CheatNotes.Get(id);

                    if (instance != null)
                    {
                        instance.Name = cheatNote.Name;
                        instance.Description = cheatNote.Description;
                        instance.DateModified = DateTime.Now;
                        instance.ModifiedById = GetCurrentUserId();
                    }

                    db.Entry(instance).State = EntityState.Modified;
                    db.SaveChanges();
                }

                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
コード例 #4
0
 public GenerateHtmlFilesModel(CheatNote cheatNote)
 {
     CheatNoteId = cheatNote.Id;
     CheatNoteName = cheatNote.Name;
     CheatNoteItemsTotal = cheatNote.Items.Count;
 }