Exemplo n.º 1
0
        public ActionResult EditNote(NoteViewModel model, IEnumerable <HttpPostedFileBase> files)
        {
            if (!ModelState.IsValid)
            {
                ModelState.AddModelError("", "Проверьте, что заполнены все поля! 😊");
                return(PartialView(model));
            }
            if (!ModelState.IsValid)
            {
                return(PartialView(model));
            }

            var UserRepository = new IH.IhudBlog.Core.NHibernate.NHUserRepository();

            User UserNote = UserRepository.LoadById(model.UserId);

            model.User = UserNote;

            Note SaveNote = new Note();

            SaveNote = NoteViewModel.Conversion(model);

            NoteRepository = new IH.IhudBlog.Core.NHibernate.NHNoteRepository();

            NoteRepository.Save(SaveNote);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public ActionResult DeleteNote(NoteViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var UserRepository = new IH.IhudBlog.Core.NHibernate.NHUserRepository();

            User UserNote = UserRepository.LoadById(model.UserId);

            model.User = UserNote;

            Note SaveNote = new Note();



            SaveNote            = NoteViewModel.Conversion(model);
            SaveNote.NoteStatus = 2;

            NoteRepository = new NHNoteRepository();

            NoteRepository.Save(SaveNote);


            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public IEnumerable <Note> GetAllValid()
        {
            NHUserRepository UserRep = new NHUserRepository();

            User CurrrentUser = UserRep.LoadByName(HttpContext.Current.User.Identity.Name);

            ISession session = NHibernateHelper.GetCurrentSession();

            var criteria = session.CreateCriteria <Note>().Add(Expression.Eq("NoteStatus", 1)).Add(Expression.Or(
                                                                                                       Expression.Eq("User", CurrrentUser),
                                                                                                       Expression.Eq("IsDraft", false)
                                                                                                       ));

            var entities = criteria.List <Note>();

            NHibernateHelper.CloseSession();

            return(entities);
        }
Exemplo n.º 4
0
        public static Note Conversion(NoteViewModel note)
        {
            //var StartData = Note.GetNotes();
            NHUserRepository NhuserRepository = new IH.IhudBlog.Core.NHibernate.NHUserRepository();
            User             user             = new User();

            user = NhuserRepository.LoadByName(HttpContext.Current.User.Identity.Name);

            Note result = new Note
            {
                Id           = (long)note.Id,
                IsDraft      = note.IsDraft,
                Title        = note.Title,
                Text         = note.Text,
                User         = user,
                Tags         = note.Tags == null ? "" : note.Tags,//String.Join(" ", note.Tags?.ToArray()),
                ChangeTime   = DateTime.Now,
                CreationTime = note.CreationTime == null ? DateTime.Now : note.CreationTime,
                NoteStatus   = 1
            };

            return(result);
        }