Beispiel #1
0
        public void Insert(CVDTO dto)
        {
            ATPEntities context = new ATPEntities();

            context.CV.Add(Convert(dto));
            context.SaveChanges();
        }
Beispiel #2
0
        public void Delete(int id)
        {
            ATPEntities context = new ATPEntities();

            context.CV.Remove(context.CV.FirstOrDefault(element => element.ID == id));
            context.SaveChanges();
        }
Beispiel #3
0
        }//Edit a box with the specified by the DTO ID

        public BoxDTO Get(int id)
        {
            ATPEntities _dbContext = new ATPEntities();                                                //Create connection
            BOX         box        = _dbContext.BOX.Where(entity => entity.ID == id).FirstOrDefault(); //Find box with id or return null

            return(Convert(box));                                                                      //Convert to DTO and return
        }//Gets a box with the specified ID
Beispiel #4
0
        //Insert a user to the database
        public void Insert(UserDTO user)
        {
            ATPEntities _dbContext = new ATPEntities(); //Database context(database connection)

            _dbContext.USER_NEW_NEW.Add(Convert(user)); //Map DTO to Database Object
            _dbContext.SaveChanges();                   //ALWAYS SAVE AFTER BEING DONE. Make only one transfer to the database for safety reasons
        }//Adds a user to the database
Beispiel #5
0
        }//Adds a box to the database

        public void Delete(int id)
        {
            ATPEntities _dbContext = new ATPEntities();//Create connection

            //Remove box if it exists
            _dbContext.BOX.Remove(_dbContext.BOX.Where(entity => entity.ID == id).FirstOrDefault());
            _dbContext.SaveChanges();//Save Changes to the database
        }//Removes a box with the specified ID
Beispiel #6
0
        public void Insert(BoxDTO box)
        {
            ATPEntities _dbContext = new ATPEntities(); //Create connection

            _dbContext.BOX.Add(Convert(box));           //Add box to database

            _dbContext.SaveChanges();                   //Save Changes to the database
        }//Adds a box to the database
Beispiel #7
0
        }//Edit a user by a specified from the DTO ID

        public UserDTO Get(int id)
        {
            ATPEntities _dbContext = new ATPEntities(); //Database context(database connection)
            //Get User if there exists one with the specified username and convert to DTO
            USER_NEW_NEW userEntity = _dbContext.USER_NEW_NEW.FirstOrDefault(user => user.ID == id);

            return(Convert(userEntity));
        }//Get a user by a specified ID
Beispiel #8
0
        }//Get a user by a specified ID

        public void Delete(int id)
        {
            ATPEntities _dbContext = new ATPEntities(); //Database context(database connection)

            //Remove user if there exists one with the specified username
            _dbContext.USER_NEW_NEW.Remove(_dbContext.USER_NEW_NEW.FirstOrDefault(user => user.ID == id));
            _dbContext.SaveChanges();//ALWAYS SAVE AFTER BEING DONE. Make only one transfer to the database for safety reasons
        }//Delete a user by a specified ID
Beispiel #9
0
        }//Gets a box with the specified ID

        public IEnumerable <BoxDTO> GetAll()
        {
            ATPEntities _dbContext = new ATPEntities();//Create connection

            foreach (BOX box in _dbContext.BOX)
            {
                yield return(Convert(box));
            }
        }//Gets all boxes as an IEnumerable
Beispiel #10
0
        }//Get a user by a specified ID

        public IEnumerable <UserDTO> GetAll()
        {
            ATPEntities _dbContext = new ATPEntities(); //Database context(database connection)

            foreach (USER_NEW_NEW user in _dbContext.USER_NEW_NEW)
            {
                yield return(Convert(user));
            }
        }//Get all users
Beispiel #11
0
        }//Adds a user to the database

        public bool Has(int id)
        {
            ATPEntities _dbContext = new ATPEntities(); //Database context(database connection)

            //Return true if there exists a user
            return(_dbContext
                   .USER_NEW_NEW
                   .FirstOrDefault(entity => entity.ID == id) != null);
        }//Get a user by a specified ID
Beispiel #12
0
        }//Removes a box with the specified ID

        public void Edit(BoxDTO dto)
        {
            ATPEntities _dbContext = new ATPEntities();                                                    //Create connection
            BOX         old        = _dbContext.BOX.Where(entity => entity.ID == dto.ID).FirstOrDefault(); //Get the old box
            BOX         newBOX     = Convert(dto);                                                         //Create a new box from a conversion

            foreach (PropertyInfo property in old.GetType().GetProperties().Where(property => property.Name != "ID"))
            {
                property.SetValue(old, property.GetValue(newBOX)); // set the values of the old box to the values of the new one
            }
            _dbContext.SaveChanges();                              //Save Changes to the database
        }//Edit a box with the specified by the DTO ID
Beispiel #13
0
        }//Delete a user by a specified ID

        public void Edit(UserDTO dto)
        {
            ATPEntities  _dbContext = new ATPEntities(); //Database context(database connection)
            USER_NEW_NEW userOld    = _dbContext.USER_NEW_NEW.FirstOrDefault(user => user.USERNAME == dto.Username);
            USER_NEW_NEW userNew    = Convert(dto);

            //Map values from new entity to the existing version because this is how it must be done
            foreach (PropertyInfo property in userOld.GetType().GetProperties())
            {
                property.SetValue(userOld, property.GetValue(userNew));
            }
            _dbContext.SaveChanges();//ALWAYS SAVE AFTER BEING DONE. Make only one transfer to the database for safety reasons
        }//Edit a user by a specified from the DTO ID
Beispiel #14
0
        public void Edit(CVDTO dto)
        {
            ATPEntities context = new ATPEntities();
            CV          entity  = context.CV.FirstOrDefault(element => element.ID == dto.ID);

            entity.Address     = dto.Address;
            entity.Education   = dto.Education;
            entity.Email       = dto.Email;
            entity.Experience  = dto.Experience;
            entity.FirstName   = dto.FirstName;
            entity.ID          = dto.ID;
            entity.LastName    = dto.LastName;
            entity.Qualities   = dto.Qualities;
            entity.Picture     = dto.PictureBytes;
            entity.PictureName = dto.PictureName;
            context.SaveChanges();
        }