Exemplo n.º 1
0
        public ActionResult NewUser(UserInfo us)
        {
            us.JoiningDate         = DateTime.Now;
            us.TotalEventsAttended = us.TotalHostedEvents = us.TotalParticipants = 0;
            usrepo.Insert(us);
            HttpPostedFileBase file1 = Request.Files[0];
            HttpPostedFileBase file2 = Request.Files[1];

            if (file1.ContentLength > 0)
            {
                var fileName = us.UserID + Path.GetExtension(file2.FileName);
                us.Portfolio = fileName;
                var path = Path.Combine(Server.MapPath("~/App_Data/Portfolio"), fileName);
                file2.SaveAs(path);
            }
            if (file2.ContentLength > 0)
            {
                var fileName = us.UserID + Path.GetExtension(file1.FileName);
                us.ProfilePic = fileName;
                var path = Path.Combine(Server.MapPath("~/App_Data/ProPic"), fileName);
                file1.SaveAs(path);
            }
            usrepo.Update(us);
            return(View());
        }
Exemplo n.º 2
0
 public Result Add([FromForm] string name, [FromForm] string password)
 {
     if (!User.Super)
     {
         return(Fail("添加用户失败,你没有权限操作"));
     }
     try
     {
         if (_repository.Exists(n => n.Name == name))
         {
             return(Fail("用户名称已存在!"));
         }
         UserInfo user = new UserInfo {
             Name = name, Password = UserUtility.EncryptPassword(password)
         };
         if (_repository.Insert(user) <= 0)
         {
             return(Fail("添加用户失败!"));
         }
         user.Password = password;
         return(Success(user, "添加成功!"));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message + ex.StackTrace);
         return(Fail("系统错误"));
     }
 }
Exemplo n.º 3
0
 public ActionResult Create(userInfo userInfo, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         bool EmailAlreadyAdded = context.userInfoes.Any(x => x.Email == userInfo.Email);
         if (EmailAlreadyAdded)
         {
             TempData["EmailExist"] = "This email is Already in use";
         }
         if (file != null)
         {
             string path = null;
             if (file.ContentType == "image/png" || file.ContentType == "image/jpeg" || file.ContentType == "image/jpg")
             {
                 path = Path.Combine(Server.MapPath("~/Content/Images/"), Path.GetFileName(file.FileName));
                 file.SaveAs(path);
                 if (path != null)
                 {
                     file.SaveAs(path);
                     userInfo.ProPic = file.FileName;
                     userInfoRepository.Insert(userInfo);
                     return(RedirectToAction("Login", "Home"));
                 }
             }
         }
     }
     return(View());
 }
Exemplo n.º 4
0
        public ActionResult SignUp(UserInfo us)
        {
            us.AccountTypeID       = 2;
            us.StatusID            = 1;
            us.JoiningDate         = DateTime.Now;
            us.TotalEventsAttended = us.TotalHostedEvents = us.TotalParticipants = 0;
            UsRepo.Insert(us);


            return(RedirectToAction("Login"));
        }
Exemplo n.º 5
0
        public int RegisterUser(UserRegistrationDto userRegistrationDto)
        {
            UserLoginDto userLogin = userRegistrationDto.LoginInfo;
            UserInfoDto  userInfo  = userRegistrationDto.UserInfo;
            int          userId;

            try
            {
                if (userLogin == null)
                {
                    throw new ArgumentNullException("User Login Information cannot be null");
                }

                if (userInfo == null)
                {
                    throw new ArgumentNullException("User Information cannot be null");
                }

                using (UserLoginRepository userLoginRepository = new UserLoginRepository())
                {
                    UserLogin userLoginEntity = userLoginRepository.Find(x => x.EmployeeId == userLogin.EmployeeId);
                    if (userLoginEntity != null)
                    {
                        throw new Exception("User with same employee id already exists.");
                    }
                    else
                    {
                        userLoginEntity = new UserLogin()
                        {
                            EmployeeId = userLogin.EmployeeId,
                            Password   = userLogin.Password.Encrypt(),
                            IsActive   = true,
                            IsLocked   = false,
                            RetryCount = 0
                        };
                        userId = userLoginRepository.Insert(userLoginEntity);
                    }
                }
                if (userId != 0)
                {
                    using (UserInfoRepository userInfoRepository = new UserInfoRepository())
                    {
                        UserInfo userInfoEntity = new UserInfo()
                        {
                            EmployeeId = userInfo.EmployeeId,
                            EMail      = userInfo.Email,
                            FirstName  = userInfo.FirstName,
                            LastName   = userInfo.LastName,
                            Gender     = userInfo.Gender
                        };
                        return(userInfoRepository.Insert(userInfoEntity));
                    }
                }
                else
                {
                    throw new Exception("Failed to register user.");
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                throw;
            }
        }
Exemplo n.º 6
0
 public void Post([FromBody] UserInfo user)
 {
     UserInfoRepository.Insert(user);
 }