Esempio n. 1
0
 public Unit getUnit(int userId)
 {
     Unit unit = new Unit();
     foreach (List<string> data in database.retrieveData("select un.id, un.name from lds_user us, lds_unit un, lds_user_unit uu  " +
         " where uu.user_id = @id " +
         "   and uu.unit_id = un.id " +
         "   and uu.user_id = us.id", userId))
     {
         unit.Id = common.convertNumber(data[0]);
         unit.Name = data[1];
     }
     return unit;
 }
Esempio n. 2
0
        public ActionResult Create(UnitViewModel model)
        {
            if (!isAuthenticated() || !loggedUser.isAdmin)
                return new HttpUnauthorizedResult();
            else
            {
                if (ModelState.IsValid)
                {
                    User user = (User)Session["user"];

                    Unit unit = new Unit();
                    Result result = unit.addUnit(model.Name, user.Id);

                    if (result.Success)
                        return RedirectToAction("Success");
                }
                return View(model);
            }
        }
Esempio n. 3
0
        public ActionResult Create(UserViewModel model)
        {
            if (ModelState.IsValid)
            {
                Models.User newUser = new Models.User();

                // check if the email address is already being used
                if (!newUser.emailExists(model.Email))
                {
                    Result result = newUser.addUser(model.Email, model.Password);

                    if (result.Success)
                        result = new Unit().addUnit(model.UnitName, result.Id);

                    if (result.Success)
                        return RedirectToAction("Success");
                }
                else
                {
                    ModelState.AddModelError("", pt_br.EmailAlreadyBeingUsed);
                }
            }
            return View(model);
        }
Esempio n. 4
0
        public ActionResult Update(UserViewModel model)
        {
            if (!isAuthenticated())
                return new HttpUnauthorizedResult();
            else
            {
                if (ModelState.IsValid)
                {
                    if (model.Password != string.Empty && model.Email != string.Empty)
                    {
                        Models.User user = new Models.User();
                        string oldEmail = user.getUser(model.Id).Email;
                        bool emailOk = false;

                        // check if the email id different
                        if (oldEmail.ToLower() == model.Email.ToLower())
                            emailOk = true;
                        else
                        {
                            if (!user.emailExists(model.Email))
                                emailOk = true;
                        }

                        if (emailOk)
                        {
                            Result result = user.updateUser(model.Id, model.Email, model.Password);

                            if (result.Success)
                                result = new Unit().updateUnit(model.UnitName, model.Id);

                            if (result.Success)
                            {
                                Session["user"] = new User().getUser(model.Id);
                                return RedirectToAction("UpdateSuccess");
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "Endereço de email já está sendo utilizado por outro usuário");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "Os campos email e senha precisam ser preenchidos");
                    }
                }

                ViewBag.isAdmin = loggedUser.isAdmin;

                return View(model);
            }
        }
Esempio n. 5
0
 public User getUser(string email)
 {
     User user = new User();
     foreach (List<string> data in database.retrieveData("select id, profile from lds_user where email = @email", email))
     {
         user.Id = Convert.ToInt32(data[0]);
         user.Email = email;
         user.isAdmin = (data[1] == "1");
         Unit unit = new Unit().getUnit(user.Id);
         user.Unit = unit.Id;
         user.UnitName = unit.Name;
     }
     return user;
 }
Esempio n. 6
0
 public User getUser(int id)
 {
     User user = new User();
     foreach(List<string> data in database.retrieveData("select email, password, profile from lds_user where id = @id", id))
     {
         user.Id = id;
         user.Email = data[0];
         user.Password = data[1];
         user.isAdmin = (data[2] == "1");
         Unit unit = new Unit().getUnit(id);
         user.Unit = unit.Id;
         user.UnitName = unit.Name;
     }
     return user;
 }