public ActionResult AddNote(Models.Notes model)
        {
            string emailID = (string)Session["User"];
            Note   entity  = new Note();

            entity.Note1 = model.Note;
            if (model.share.Contains("Private with me"))
            {
                entity.share = model.share;
            }
            else
            {
                var shared = repo.userAccessByID(Convert.ToInt32(model.share));
                entity.share = shared.EmailID;
            }

            entity.PostedBy = emailID;
            bool status = repo.addNotes(entity, emailID);

            if (status)
            {
                return(RedirectToAction("GetNotes", "Home"));
            }
            else
            {
                ViewBag.NoteMsg = "Oops Something went wrong Please try again later";
                return(View(model));
            }
        }
 public ActionResult Edit([Bind(Include = "Id,UserId,Content")] Models.Notes note)
 {
     if (ModelState.IsValid)
     {
         db.Entry(note).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index", "Notes", new { userId = note.UserId }));
     }
     return(View(note));
 }
        public ActionResult Create([Bind(Include = "Id,UserId,Content")] Models.Notes note)
        {
            if (ModelState.IsValid)
            {
                db.Notes.Add(note);
                db.SaveChanges();
                return(RedirectToAction("Index", "Notes", new { userId = note.UserId }));
            }

            return(View(note));
        }
Beispiel #4
0
        /// <summary>
        /// Get by id. if id=0 get all. if filter not empty then apply filter
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Models.Notes Get(int id)
        {
            // get all - open text file, loop over every item
            Models.Notes thenotes = new Models.Notes();

            fileCheck(sfilepath);
            int lineno = 0;

            using (StreamReader sr = new StreamReader(sfilepath))
            {
                String aline = "";
                if (id > 0)
                {  // skip to specific item
                    while ((aline = sr.ReadLine()) != null)
                    {
                        lineno++;
                        if (lineno < id)
                        {
                            continue;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (aline == null)
                    {
                        aline = "";
                    }
                    if (aline.Length > 0)
                    {
                        Models.NoteModel anote = new Models.NoteModel(lineno, aline);
                        thenotes.notes.Add(anote);
                    }
                }

                else   // pid=0 or invalid or blank
                       // read all
                {
                    while ((aline = sr.ReadLine()) != null)
                    {
                        lineno++;
                        if (aline.Length > 0)
                        {
                            if (sfilter.Length == 0 || (sfilter.Length > 0 && aline.ToLower().Contains(sfilter.ToLower())))
                            {
                                Models.NoteModel anote = new Models.NoteModel(lineno, aline);
                                thenotes.notes.Add(anote);
                            }
                        }
                        if (id > 0) // onlywant 1
                        {
                            break;
                        }
                    }
                }
                sr.Dispose();
            }
            if (thenotes.notes.Count == 0)
            {
                if (id > 0)
                {
                    Models.NoteModel anote = new Models.NoteModel(id, "Note not found");
                    thenotes.notes.Add(anote);
                }
                else
                {
                    Models.NoteModel anote = new Models.NoteModel(-1, "Notes are empty");
                    thenotes.notes.Add(anote);
                }
            }
            return(thenotes);
        }