Exemplo n.º 1
0
 /// <summary>
 /// Modify User
 /// </summary>
 /// <param name="User"></param>
 public void ModifyUser(Model.ViewModel.User User)
 {
     if (UserIdExists(User.Id))
     {
         T_USER NewUserEntity = UMapper.MapToEntity(User);
         Db.Attach(NewUserEntity);
         Db.Entry(NewUserEntity).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
         Db.SaveChanges();
     }
     else
     {
         throw new UserNotFoundException();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Add new user to database
        /// </summary>
        /// <param name="User"></param>
        public void AddUser(Model.ViewModel.User User)
        {
            T_USER UserEntity = UMapper.MapToEntity(User);

            if (!UserNameExists(UserEntity.NAME))
            {
                //Set Id to zero because database is set to autoincrement
                UserEntity.OID = 0;
                Db.T_USER.Add(UserEntity);
                Db.SaveChanges();
            }
            else
            {
                throw new UserAlreadyExistsException();
            }
        }