Example #1
0
 public ActionResult Create(User model)
 {
     try
     {
         var currentuser = this.GetCurrentUser();
         if (currentuser != null && currentuser.Role == Role.Manager)
         {
             var user = new User()
             {
                 UserName = model.UserName,
                 Password = model.Password,
                 Role = model.Role
             };
             this.UserRepository.Add(user);
             this.UserRepository.SaveChanges();
             return RedirectToAction("Index");
         }
         else
         {
             throw new HttpException(404, "");
         }
     }
     catch
     {
         return View();
     }
 }
Example #2
0
 // GET: Base
 public PartialViewResult LoginStatu()
 {
     var user = new User();
     if (string.IsNullOrEmpty(this.User.Identity.Name))
         user = null;
     else
         user = this.UserRepository.Load(int.Parse(this.User.Identity.Name));
     return PartialView("_LoginStatu", user);
 }
Example #3
0
        public ActionResult Edit(User model)
        {
            try
            {
                var currentuser = this.GetCurrentUser();
                if ((currentuser != null && currentuser.Role == Role.Manager) || (currentuser != null && currentuser.Id == model.Id))
                {
                    var user = this.UserRepository.Load(model.Id);
                    user.Password = StringHelper.Md5(model.Password);
                    user.Role = model.Role;
                    this.UserRepository.SaveChanges();

                    return RedirectToAction("Index");
                }
                else
                {
                    throw new HttpException(404, "");
                }
            }
            catch
            {
                return View();
            }
        }