Exemplo n.º 1
0
        /// <summary>
        /// Delete specified user from database
        /// </summary>
        /// <param name="user">dot User data</param>
        public void DeleteUser(UserDto dto)
        {
            try
            {
                //Before any action, it must be updated because calls from contract uses
                //only one instance of UserManager.
                dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.Users);

                //Find user which has been deleted.
                User existingUser = (User)dbContext.Users.Single(u => u.Id == dto.UserId);

                //If required user doesn't exists, throw exception.
                if (existingUser == null)
                {
                    throw new Exception("Users does not exist");
                }
                //else perform deleting from database
                else
                {
                    //Delete user.
                    dbContext.DeleteObject(existingUser);

                    //Saves chages.
                    dbContext.SaveChanges();
                }

            }
            catch (Exception exception)
            {
                throw new Exception("SmartGridDataMenagers: " + exception.Message);
            }
        }
Exemplo n.º 2
0
 public void UserDtoConstructorTest()
 {
     int userId = 0; // TODO: Initialize to an appropriate value
     string userName = string.Empty; // TODO: Initialize to an appropriate value
     string userPassword = string.Empty; // TODO: Initialize to an appropriate value
     UserDto target = new UserDto(userId, userName, userPassword);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }
Exemplo n.º 3
0
 public void UserIdTest()
 {
     UserDto target = new UserDto(); // TODO: Initialize to an appropriate value
     int expected = 0; // TODO: Initialize to an appropriate value
     int actual;
     target.UserId = expected;
     actual = target.UserId;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns list of all users from database.
        /// </summary>
        /// <returns>List list of UserDto's</returns>
        public List<UserDto> GetAllUsers()
        {
            //Instantiate list of dto users which has been returned.
            List<UserDto> listDto = new List<UserDto>();
            try
            {
                //Before any action, it must be updated because calls from contract uses
                //only one instance of UserManager.
                dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.Users);

                //list of users
                List<User> list = dbContext.Users.OrderBy(u => u.Id).ToList();

                //filling the list
                foreach (User u in list)
                {
                    UserDto userDto = new UserDto(u.Id, u.UserName, u.UserPassword);
                    listDto.Add(userDto);
                }

            }
            catch (Exception exception)
            {
                throw new Exception("UserDataMenager: " + exception.Message);
            }
            //returns list of all users as list of dtoes.
            return listDto;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Update User data in database
        /// </summary>
        /// <param name="dto">dto user data</param>
        public void UpdateUser(UserDto dto)
        {
            try
            {
                //Before any action, it must be updated because calls from contract uses
                //only one instance of UserManager.
                dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.Users);

                //Find user which have to bee updated.
                User existingUser = dbContext.Users.Single(u => u.Id == dto.UserId);

                //If required user doesn't exists, throw exception.
                if (existingUser == null)
                {
                    throw new Exception("User does not exist");
                }
                //else prepare all data for storing to database.
                else
                {
                    existingUser.UserName = dto.UserName;
                    existingUser.UserPassword = dto.UserPassword;
                }
                //Save changes
                dbContext.SaveChanges();
            }
            catch (Exception exception)
            {
                throw new Exception("UserDataMenagers: " + exception.Message);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Insert specified user in database
        /// </summary>
        /// <param name="dto">dto data for user</param>
        public void InsertUser(UserDto dto)
        {
            try
            {
                //Before any action, it must be updated because calls from contract uses
                //only one instance of UserManager.
                dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, dbContext.Users);
                //New user - setting data
                User u = new User();
                u.UserName = dto.UserName;
                u.UserPassword = dto.UserPassword;

                //Adds new user to context
                dbContext.Users.AddObject(u);

                //saves changes.
                dbContext.SaveChanges();
            }
            catch (Exception exception)
            {
                throw new Exception("UserDataMenagers: " + exception.Message);
            }
        }
Exemplo n.º 7
0
 public void UserNameTest()
 {
     UserDto target = new UserDto(); // TODO: Initialize to an appropriate value
     string expected = string.Empty; // TODO: Initialize to an appropriate value
     string actual;
     target.UserName = expected;
     actual = target.UserName;
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Exemplo n.º 8
0
 public void UserDtoConstructorTest1()
 {
     UserDto target = new UserDto();
     Assert.Inconclusive("TODO: Implement code to verify target");
 }