예제 #1
0
        public ActionResult Create(User model)
        {
            try
            {
                // TODO: Add insert logic here
                if (ModelState.IsValid)
                {

                    var user = ObjUserService.Add(model);
                    if (user.UserName == CustomErrorHelper.UserAlreadyExist)
                    {
                        ModelState.AddModelError(CustomErrorHelper.UserAlreadyExist, CustomErrorHelper.UserAlreadyExist);
                        return View(model);
                    }
                    else if (user.EmailId == CustomErrorHelper.EmailAlreadyExist)
                    {
                        ModelState.AddModelError(CustomErrorHelper.EmailAlreadyExist, CustomErrorHelper.EmailAlreadyExist);
                        return View(model);
                    }
                    return RedirectToAction("List");
                }
                else
                {
                    return View(model);
                }

            }
            catch
            {
                return View();
            }
        }
예제 #2
0
 public bool CheckLogin(User entity)
 {
     // Func<User, bool> userfunc = x => (entity.UserName == x.UserName) ;
     var user = repository.Get(x => (entity.UserName == x.UserName));
     if (user == null)
     {
         return false;
     }
     if (user.Active == false)
     {
         return false;
     }
     return EncryptionHelper.Encrypt(entity.Password) == user.Password;
 }
예제 #3
0
 public User Add(User entity)
 {
     entity.Password = EncryptionHelper.Encrypt(entity.Password);
     User entity1 = entity;
     var user = repository.Get(x => (x.UserName == entity1.UserName));
     if (user != null)
     {
         user.UserName = CustomErrorHelper.UserAlreadyExist;
         return user;
     }
     user = repository.Get(x => (x.EmailId == entity1.EmailId));
     if (user != null)
     {
         user.EmailId = CustomErrorHelper.EmailAlreadyExist;
         return user;
     }
     entity = repository.Add(entity);
     unitOfWork.Commit();
     return entity;
 }
예제 #4
0
        private void SetLoginSession(User user)
        {
            var session = new UserSession(user.Id, user.UserName);

            UserSession.SetSession(session);
            int userid = UserSession.GetSession().UserId;
            FormsAuthentication.SetAuthCookie(user.UserName, false);
        }
예제 #5
0
        public ActionResult Index(User user)
        {
            if (Session["Captcha"] == null || Session["Captcha"].ToString() != user.Captcha)
            {
                foreach (var modelValue in ModelState.Values)
                {
                    modelValue.Errors.Clear();
                }
                ModelState.AddModelError("Captcha", "Wrong value of sum, please try again.");
                return View(user);
            }

            if (ObjUserService.CheckLogin(user))
            {
                SetLoginSession(user);
                //Need Refractor on this

                Response.Redirect(FormsAuthentication.DefaultUrl, false);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("Error", "Username or Password didnot match");
                return View();
            }
        }
예제 #6
0
 public ActionResult Edit(int id, User user)
 {
     try
     {
         //var entity = ObjUserService.GetById(id);
         //user.Password = entity.Password;
         if (ModelState.IsValid)
         {
             ObjUserService.Update(user);
             return RedirectToAction("List");
         }
         else
         {
             return View(user);
         }
     }
     catch (Exception ex)
     {
         ModelState.AddModelError("Error", ex.Message);
         return View(user);
     }
 }
예제 #7
0
 public User Update(User entity)
 {
     entity = repository.Update(entity);
     unitOfWork.Commit();
     return entity;
 }
예제 #8
0
 public void Delete(User entity)
 {
     repository.Delete(entity);
     unitOfWork.Commit();
 }