Exemplo n.º 1
0
        public ActionResult Add(NotesModel model)
        {
            //if model contains value for ID then edit record or create new record
            using (entity.encoraEntities context = new entity.encoraEntities())
            {
                entity.note note = null;
                if (model.ID > 0)
                {
                    note             = context.notes.Where(o => o.id == model.ID).FirstOrDefault();
                    note.description = model.Description;
                    note.isArchived  = model.isArchived;
                    note.modified    = DateTime.Now;
                    ViewBag.Message  = "Data updated successfully";
                }
                else
                {
                    note = context.notes.Create();

                    note.description = model.Description;
                    note.userID      = Convert.ToInt32(Session["UserID"]);
                    note.created     = DateTime.Now;
                    note.modified    = DateTime.Now;
                    note.isArchived  = model.isArchived;
                    context.notes.Add(note);
                    ViewBag.Message = "Data insert successfully";
                }

                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 2
0
        public ActionResult Index()
        {
            entity.encoraEntities entity = new entity.encoraEntities();

            //All notes records are taken here
            var data = entity.notes;

            return(View(data.ToList()));
        }
Exemplo n.º 3
0
        public ActionResult Delete(int id)
        {
            entity.encoraEntities context = new entity.encoraEntities();

            var data = context.notes.Where(x => x.id == id).FirstOrDefault();

            context.notes.Remove(data);
            context.SaveChanges();

            ViewBag.Messsage = "Record delete successfully";
            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
 public Models.UserModel Login(Models.UserModel user)
 {
     //user name and password validated with database entries (password is plain text here not used any encrytion )
     using (entity.encoraEntities context = new entity.encoraEntities())
     {
         bool IsValidUser = context.users.Any(o => o.userName.ToLower() ==
                                              user.UserName.ToLower() && o.password == user.UserPassword);
         if (IsValidUser)
         {
             var userDetails = context.users.Where(o => o.userName.ToLower() ==
                                                   user.UserName.ToLower() && o.password == user.UserPassword).FirstOrDefault();
             user.ID       = userDetails.id;
             user.Created  = userDetails.created;
             user.Modified = userDetails.modified;
             return(user);
         }
         user.ErrorMessage = "invalid Username or Password";
     }
     return(user);
 }
Exemplo n.º 5
0
        public ActionResult Add(int?id)
        {
            //if id has value then make edit the record
            if (id.HasValue)
            {
                entity.encoraEntities context = new entity.encoraEntities();

                var data = context.notes.Where(x => x.id == id).FirstOrDefault();

                return(View(new NotesModel()
                {
                    ID = data.id,
                    Created = data.created,
                    Modified = data.modified,
                    Description = data.description,
                    isArchived = data.isArchived.Value,
                    UserID = data.userID
                }));
            }
            return(View());
        }