Пример #1
0
 public ActionResult Create(UserViewModel userVM)
 {
     if (ModelState.IsValid)
     {
         User       user = UserViewModel.Converter(userVM);
         UserDALImp imp  = new UserDALImp();
         string     msg  = imp.ValidationUserCreation(user);
         if (msg.Equals(""))
         {
             user = imp.Create(user);
             if (user != null)
             {
                 TempData["msg"]    = "El usuario fue creado";
                 TempData["status"] = true;
                 return(RedirectToAction("Index"));
             }
             else
             {
                 ViewBag.msg    = "El usuario no pudo ser creado";
                 ViewBag.status = false;
             }
         }
         else
         {
             ViewBag.msg    = msg;
             ViewBag.status = false;
         }
     }
     else
     {
         ViewBag.msg    = "Revisa la informacion del usuario";
         ViewBag.status = false;
     }
     return(View(userVM));
 }
Пример #2
0
        public ActionResult Index()
        {
            if (TempData["msg"] != null)
            {
                ViewBag.msg    = TempData["msg"].ToString();
                ViewBag.status = Boolean.Parse(TempData["status"].ToString());
                TempData.Remove("msg");
                TempData.Remove("status");
            }
            List <User> users;

            using (var unit = new UnitWork <User>()) {
                users = unit.genericDAL.GetAll().ToList();
            }
            List <UserViewModel> us = new List <UserViewModel>();

            if (users != null)
            {
                string key = ConfigurationManager.AppSettings["SecretKey"];
                us = UserViewModel.Converter(users);
                foreach (var u in us)
                {
                    u.email = Security.Security.DecryptString(key, u.email);
                }
            }
            return(View("index", us));
        }
Пример #3
0
 public void OnAuthorization(AuthorizationContext filterContext)
 {
     if (filterContext.RequestContext.HttpContext.Request.IsAuthenticated)
     {
         IUserDAL us   = new UserDALImp();
         User     user = us.Get_User(Convert.ToInt32(filterContext.RequestContext.HttpContext.User.Identity.Name));
         if (user != null)
         {
             if (!user.active)
             {
                 //ViewBag.Desactivado = true;
                 filterContext.RequestContext.HttpContext.RedirectLocal("/Home/Index");
             }
             else
             {
                 UserViewModel userV = UserViewModel.Converter(user);
                 Assistance    a     = loadAssistance(user.idUser);
                 if (a != null)
                 {
                     userV.assistance = a;
                 }
                 filterContext.RequestContext.HttpContext.Session["User"] = userV;
             }
         }
         else
         {
             if (!filterContext.RequestContext.HttpContext.Request.Url.AbsolutePath.Equals("/Home/Index"))
             {
                 filterContext.Result = new RedirectToRouteResult("/Home/Index", null);
                 //filterContext.RequestContext.HttpContext.Response.Redirect("/Home/Index");
             }
         }
     }
 }
Пример #4
0
        public ActionResult Details(int id)
        {
            User       us;
            UserDALImp imp = new UserDALImp();

            us = imp.Get_User(id);
            return(View(UserViewModel.Converter(us)));
        }
Пример #5
0
        public ActionResult Index(LogInViewModel loginM)
        {
            try {
                QRImpl QRimpl  = new QRImpl();
                string baseUrl = Request.Url.Scheme + "://" + Request.Url.Authority + "/";
                byte[] QRimage = QRimpl.Get_QR_Asistance(baseUrl + "/Assistance/CreateAssistance");
                if (QRimage != null)
                {
                    ViewBag.QRAsistance = QRimage;
                }
                if (ModelState.IsValid)
                {
                    //Obtengo el usuario
                    IUserDAL us   = new UserDALImp();
                    User     user = us.Validate_LogIn(loginM.Correo, loginM.Clave);

                    if (user == null)
                    {
                        ViewBag.wrongCredentials = true;
                        return(View(loginM));
                    }
                    else if (!user.active)
                    {
                        ViewBag.inactive = true;
                        return(View(loginM));
                    }
                    else
                    {
                        //Obtengo los roles
                        List <string> ListaRoles = new List <string>();
                        ListaRoles.Add(user.rol);
                        var roles = String.Join(",", ListaRoles);

                        //Autetico el usuario y guardo algunos de sus datos y sus roles en la sesión
                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.idUser.ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), loginM.Recordarme, roles, FormsAuthentication.FormsCookiePath);
                        string     hash   = FormsAuthentication.Encrypt(ticket);
                        HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, hash);

                        if (ticket.IsPersistent)
                        {
                            cookie.Expires = ticket.Expiration;
                        }

                        Response.Cookies.Add(cookie);

                        Session["User"] = UserViewModel.Converter(user);

                        return(RedirectToAction("UserHome"));
                    }
                }
                else
                {
                    return(View(loginM));
                }
            } catch (Exception e) {
                return(new HttpNotFoundResult(e.Message));
            }
        }
Пример #6
0
        public ActionResult Edit(UserViewModel userVM)
        {
            bool result = false;
            User aux;

            using (var unit = new UnitWork <User>()) {
                aux = unit.genericDAL.Get(userVM.idUser);
            }
            if (aux != null)
            {
                userVM.password = aux.password;
                if (!userVM.rol.Equals("C"))
                {
                    userVM.height = 10;
                    userVM.weight = 10;
                }
            }
            if (ModelState.IsValid)
            {
                UserDALImp imp = new UserDALImp();
                string     msg = imp.ValidationUserCreation(UserViewModel.Converter(userVM));
                if (msg.Equals(""))
                {
                    string key = ConfigurationManager.AppSettings["SecretKey"];
                    userVM.email = Security.Security.EncryptString(key, userVM.email);
                    User user = UserViewModel.Converter(userVM);
                    try {
                        using (var unit = new UnitWork <User>()) {
                            unit.genericDAL.Update(user);
                            result = unit.Complete();
                        }
                    } catch (Exception e) {
                        result = false;
                    }
                }
                else
                {
                    ViewBag.msg    = msg;
                    ViewBag.status = false;
                }
            }
            else
            {
                result = false;
            }

            TempData["status"] = result;
            TempData["msg"]    = (!result) ? "El usuario no se pudo crear" : "El usuario ha sido editado";
            if (result)
            {
                return(RedirectToAction("Index"));
            }
            return(View(userVM));
        }
Пример #7
0
        public ActionResult CreateAssistance()
        {
            if (Request.IsAuthenticated)
            {
                UserViewModel usu        = (UserViewModel)Session["User"];
                int           caseAction = -1;

                /*
                 * -1: to view (well)
                 * -2: already with assistance
                 * -3: Error
                 */
                if (usu != null)
                {
                    IAssistanceDAL    asis = new AssistanceDALImp();
                    AssistanceControl ac   = asis.CalcAssistante(UserViewModel.Converter(usu));
                    usu.assistance  = ac.Assistance;
                    caseAction      = ac.CaseAction;
                    Session["User"] = usu;
                }
                else
                {
                    caseAction = -3;
                }
                if (caseAction == -2)
                {
                    return(RedirectToAction("UserHome", "Home"));
                }
                else
                {
                    if (caseAction == -1)
                    {
                        ViewBag.msg    = "Se ha creado la asistencia con exito";
                        ViewBag.user   = usu;
                        ViewBag.status = true;
                    }
                    else
                    {
                        ViewBag.msg    = "No se pudo crear la asistencia";
                        ViewBag.user   = usu;
                        ViewBag.status = false;
                    }
                    return(View("AssistanceCtr"));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Пример #8
0
        public ActionResult Edit(int id)
        {
            if (TempData["msg"] != null)
            {
                ViewBag.msg = TempData["msg"].ToString();
                TempData.Remove("msg");
            }
            User       us;
            UserDALImp imp = new UserDALImp();

            us          = imp.Get_User(id);
            us.password = "******";
            if (!us.rol.Equals("C"))
            {
                us.height = 10;
                us.weight = 10;
            }
            return(View(UserViewModel.Converter(us)));
        }
Пример #9
0
        public ActionResult EditProfile(UserViewModel userVM)
        {
            string key    = ConfigurationManager.AppSettings["SecretKey"];
            bool   result = false;
            User   aux;

            using (var unit = new UnitWork <User>()) {
                aux = unit.genericDAL.Get(userVM.idUser);
            }
            if (aux != null)
            {
                userVM.password = aux.password;
                if (!userVM.rol.Equals("C"))
                {
                    userVM.height = 10;
                    userVM.weight = 10;
                }
            }
            if (ModelState.IsValid)
            {
                UserDALImp imp = new UserDALImp();
                string     msg = imp.ValidationUserCreation(UserViewModel.Converter(userVM));
                if (msg.Equals(""))
                {
                    userVM.email = Security.Security.EncryptString(key, userVM.email);
                    User user = UserViewModel.Converter(userVM);
                    try {
                        using (var unit = new UnitWork <User>()) {
                            unit.genericDAL.Update(user);
                            result = unit.Complete();
                        }
                        if (result && userVM.rol.Equals("C") && (aux.height != userVM.height || aux.weight != userVM.weight))
                        {
                            UserDataHistory udh = new UserDataHistory()
                            {
                                date   = DateTime.Now,
                                heigth = user.height,
                                weight = user.weight,
                                idUser = user.idUser
                            };
                            using (var u = new UnitWork <UserDataHistory>()) {
                                u.genericDAL.Add(udh);
                                u.Complete();
                            }
                        }
                        ViewBag.msg = (!result) ? "No se pudo actualizar el perfil" : "El perfil se ha modificado";
                    } catch (Exception e) {
                        result = false;
                    }
                }
                else
                {
                    ViewBag.msg    = msg;
                    ViewBag.status = false;
                }
            }
            else
            {
                result = false;
            }

            ViewBag.status = result;
            if (result)
            {
                userVM.password = null;
                userVM.email    = Security.Security.DecryptString(key, userVM.email);
                Session["User"] = userVM;
            }
            return(EditProfile());
        }