Пример #1
0
        public void AddPlayerDuplicate()
        {
            var model = new VmRegistry
            {
                Name          = "name",
                Sex           = 0,
                Birth         = "1996-10-29",
                Email         = "test-email",
                Id            = 3,
                Password      = "******",
                CheckPassword = "******",
                Login         = "******"
            };

            try
            {
                this._service.AddPlayer(model);
            }
            catch (DuplicateDataException e)
            {
                Console.WriteLine(e.GetErrorMessage());

                Console.WriteLine(e.Parameter);
            }
            catch
            {
                throw;
            }
        }
Пример #2
0
 public Metadata Register(VmRegistry model)
 {
     try
     {
         this._service.AddPlayer(model);
     }
     catch (LocalizedException e)
     {
         return(new Metadata(string.Empty)
         {
             Success = false,
             Message = e.Message
         });
     }
     catch
     {
         throw;
     }
     return(new Metadata("注册成功"));
 }
Пример #3
0
        public void AddPlayerShouldSuccess()
        {
            var model = new VmRegistry
            {
                Name          = "name",
                Sex           = 0,
                Birth         = "2017-5-30",
                Password      = "******",
                CheckPassword = "******",
                Email         = "email",
                Login         = "******"
            };

            try
            {
                this._service.AddPlayer(model);
            }
            catch
            {
                throw;
            }
        }
Пример #4
0
        public void AddPlayer(VmRegistry model)
        {
            ValidationProvider.Validate(model);
            var repository   = base.UnitOfWork.Repository <Player>();
            var exist_entity = repository.Queryable().FirstOrDefault(m => m.Account.Login == model.Login || m.Email == model.Email);

            if (exist_entity != null)
            {
                if (exist_entity.Email == model.Email)
                {
                    throw new DuplicateDataException("Email");
                }
                else
                {
                    throw new DuplicateDataException("Login");
                }
            }
            var entity = new Player
            {
                Name        = model.Name,
                Birth       = DateTime.Parse(model.Birth),
                Sex         = model.Sex,
                Email       = model.Email,
                ObjectState = ObjectState.Added,
                Account     = new Account
                {
                    Login       = model.Login,
                    Password    = ("GG" + model.Password + model.Login).Md5Encrypt(),
                    CreateAt    = DateTime.Now,
                    ObjectState = ObjectState.Added,
                }
            };

            repository.Insert(entity);
            base.UnitOfWork.SaveChanges();
        }