示例#1
0
 public ActionResult Edit([Bind(Include = "Session_logID,UserID,Fecha,Photo")] Session_log session_log)
 {
     if (ModelState.IsValid)
     {
         db.Entry(session_log).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.UserID = new SelectList(db.Users, "UserID", "DocumentNumber", session_log.UserID);
     return(View(session_log));
 }
示例#2
0
        public ActionResult Create(User user)
        {
            if (ModelState.IsValid)
            {
                db.Users.Add(user);
                var respuesta = DbHelper.Save(db);
                if (respuesta.Succeeded)
                {
                    //UsuariosHelper.CreateUserAsp(user.UserName, user.Rol.Name);
                    if (user.PhotoFile != null)
                    {
                        var folder   = "~/Content/photos";
                        var fileName = string.Format("user{0}.jpg", user.UserName);

                        if (FilesHelper.UploadImage(user.PhotoFile, folder,
                                                    fileName))
                        {
                            var pic = string.Format("{0}/{1}", folder, fileName);
                            user.Photo           = pic;
                            db.Entry(user).State = EntityState.Modified;
                            respuesta            = DbHelper.Save(db);
                            if (respuesta.Succeeded == false)
                            {
                                ModelState.AddModelError(string.Empty, respuesta.Message);
                                ViewBag.RolID = new SelectList(CombosHelper.GetRoles(), "RolID", "Name", user.RolID);

                                return(View(user));
                            }
                        }
                    }
                    return(RedirectToAction("Index"));
                }
                ModelState.AddModelError(string.Empty, respuesta.Message);
            }
            ViewBag.RolID = new SelectList(CombosHelper.GetRoles(), "RolID", "Name", user.RolID);
            return(View(user));
        }