예제 #1
0
 public void SaveUser(User user)
 {
     if (user.UserId == 0)
         Create(user);
     else
         Update(user);
 }
예제 #2
0
 private void Update(User user)
 {
     using (var ctx = new FightFleetDataContext())
     {
         ctx.Users.Attach(user, true);
         ctx.SubmitChanges();
     }
 }
예제 #3
0
 private void Create(User user)
 {
     ValidateUser(user);
     using (var ctx = new FightFleetDataContext())
     {
         var existingUserName = ctx.Users.FirstOrDefault(c => c.UserName.ToLower() == user.UserName.ToLower());
         if (existingUserName != null)
             throw new UserNameExistsException("Username Is In Use");
         if (user.CreatedDate == DateTime.MinValue)
             user.CreatedDate = DateTime.Now;
         user.Password = HashPassword(user.Password);
         ctx.Users.InsertOnSubmit(user);
         ctx.SubmitChanges();
     }
 }
예제 #4
0
        public JsonResult CreateUser(string userName, string password)
        {
            var user = new FightFleet.User
            {
                UserName = userName,
                Password = password
            };

            try
            {
                new UserManager().SaveUser(user);
                return(Authenticate(userName, password));
            }
            catch (UserNameExistsException)
            {
                return(Json("username not unique", JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json("error: " + ex.Message, JsonRequestBehavior.AllowGet));
            }
        }
예제 #5
0
 private void ValidateUser(User user)
 {
     if (string.IsNullOrEmpty(user.UserName))
         throw new MissingFieldException("UserName");
     if(string.IsNullOrEmpty(user.Password))
         throw new MissingFieldException("Password");
 }
예제 #6
0
 partial void DeleteUser(User instance);
예제 #7
0
 partial void UpdateUser(User instance);
예제 #8
0
 partial void InsertUser(User instance);