Exemple #1
0
        public JsonResult SaveDataInDatabase(StudentViewModel model)
        {
            var result = false;

            try
            {
                if (model.StudentId > 0)
                {
                    tbStudent Stu = db.tbStudents.SingleOrDefault(x => x.IsDeleted == false && x.StudentId == model.StudentId);
                    Stu.StudentName  = model.StudentName;
                    Stu.Email        = model.Email;
                    Stu.DepartmentId = model.DepartmentId;
                    db.SaveChanges();
                    result = true;
                }
                else
                {
                    tbStudent Stu = new tbStudent();
                    Stu.StudentName  = model.StudentName;
                    Stu.Email        = model.Email;
                    Stu.DepartmentId = model.DepartmentId;
                    Stu.IsDeleted    = false;
                    db.tbStudents.Add(Stu);
                    db.SaveChanges();
                    result = true;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public ActionResult Crear(UserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new crudDBEntities()) {
                var oExistUser = from d in db.User
                                 where d.email == model.Email
                                 select d;

                if (oExistUser.FirstOrDefault() != null)
                {
                    model.UserMessageError = "El Email ya se encuentra utilizado";
                    return(View(model));
                }


                User oUser = new User();
                oUser.name     = model.Name;
                oUser.email    = model.Email;
                oUser.edad     = model.Edad;
                oUser.password = model.Password;
                oUser.idState  = 1;

                db.User.Add(oUser);
                db.SaveChanges();
            }
            return(Redirect(Url.Content("~/User/Index")));
        }
Exemple #3
0
        public ActionResult Editar(EditUserViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            using (var db = new crudDBEntities())
            {
                User oUser = db.User.Find(model.Id);

                oUser.name  = model.Name;
                oUser.email = model.Email;
                oUser.edad  = model.Edad;

                if (model.Password != null && model.Password.Trim() != "")
                {
                    oUser.password = model.Password;
                }


                db.Entry(oUser).State = EntityState.Modified;
                db.SaveChanges();
            }
            return(Redirect(Url.Content("~/User/Index")));
        }
Exemple #4
0
 public ActionResult Eliminar2(int Id)
 {
     using (var db = new crudDBEntities())
     {
         User oUser = db.User.Find(Id);
         oUser.idState         = 3;
         db.Entry(oUser).State = EntityState.Modified;
         db.SaveChanges();
     }
     return(Content("1"));
 }