Beispiel #1
0
        public bool Delete(int id)
        {
            HouseholdEntity householdEntity  = DatabaseContext.Households.Find(id);
            HouseholdEntity householdRemoved = DatabaseContext.Households.Remove(householdEntity);

            return(householdRemoved.HouseholdId == id ? true : false);
        }
        public HouseholdDto buildDto(HouseholdEntity entity)
        {
            if (entity != null)
            {
                HouseholdDto dto = new HouseholdDto()
                {
                    HouseholdId = entity.HouseholdId,
                    Name        = entity.Name,
                    Address     = new AddressDto()
                    {
                        Address1 = entity.Address.Address1,
                        Address2 = entity.Address.Address2,
                        City     = entity.Address.City,
                        PostCode = entity.Address.PostCode,
                        Country  = entity.Address.Country
                    },
                    //Users = fillUserCollection()
                };
                return(dto);
            }
            else
            {
                throw new KeyNotFoundException();
            }

            /*
             * //  Wtf is this for?
             * ICollection<UserDto> fillUserCollection()
             * {
             *  var userEntities = DatabaseContext.Households.Find(entity.HouseholdId).Users;
             *
             *  ICollection<UserDto> usersDto = new List<UserDto>();
             *
             *  foreach (UserEntity ue in userEntities)
             *  {
             *      if (ue != null)
             *      {
             *          //usersDto.Add(userLogic.GetById(ue.UserId));
             *      }
             *  }
             *  return usersDto;
             * }
             * ICollection<ThingDto> fillThingsCollection()
             * {
             *  // create the collection of DTO Users
             *  var entityThings = DatabaseContext.Households.Find(entity.HouseholdId).Things;
             *  ICollection<ThingDto> thingsDto = new List<ThingDto>();
             *
             *  foreach (ThingEntity te in entityThings)
             *  {
             *      if (te != null)
             *      {
             *          thingsDto.Add(thingDaLogic.GetById(te.ThingId));
             *      }
             *  }
             *  return thingsDto;
             * }
             */
        }
Beispiel #3
0
        public HouseholdDto Create(HouseholdEntity newHousehold)
        {
            HouseholdEntity householdEntity = DatabaseContext.Households.Add(newHousehold);

            DatabaseContext.SaveChanges();

            HouseholdDto householdDto = buildDto(householdEntity);

            return(householdDto);
        }
        public HouseholdDto GetById(int id)
        {
            HouseholdEntity entity = DatabaseContext.Households.Find(id);

            if (entity == null)
            {
                throw new KeyNotFoundException($"Household with id [{id}] not found");
            }

            return(buildDto(entity));
        }
        public HouseholdDto Delete(int id)
        {
            HouseholdEntity householdEntity = DatabaseContext.Households.Find(id);

            if (householdEntity == null)
            {
                throw new KeyNotFoundException($"Household with id [{id}] not found");
            }

            HouseholdEntity householdRemoved = DatabaseContext.Households.Remove(householdEntity);

            return(buildDto(householdRemoved));
        }
        public HouseholdDto Create(HouseholdDto newHousehold)
        {
            HouseholdEntity entity = new HouseholdEntity()
            {
                Address = newHousehold.Address,
                Name    = newHousehold.Name,
            };

            DatabaseContext.Households.Add(entity);
            DatabaseContext.SaveChanges();

            return(buildDto(entity));
        }
Beispiel #7
0
        public HouseholdDto Update(HouseholdEntity entity)
        {
            HouseholdEntity householdEntity = DatabaseContext.Households.Find(entity.HouseholdId);

            householdEntity.Name             = entity.Name;
            householdEntity.Address.Address1 = entity.Address.Address1;
            householdEntity.Address.Address2 = entity.Address.Address2;
            householdEntity.Address.City     = entity.Address.City;
            householdEntity.Address.PostCode = entity.Address.PostCode;
            householdEntity.Address.Country  = entity.Address.Country;

            DatabaseContext.SaveChanges();

            HouseholdDto householdDto = buildDto(householdEntity);

            return(householdDto);
        }
        public HouseholdDto Update(HouseholdDto dto)
        {
            HouseholdEntity householdEntity = DatabaseContext.Households.Find(dto.HouseholdId);

            if (householdEntity == null)
            {
                throw new KeyNotFoundException($"Household with id [{dto.HouseholdId}] not found");
            }

            householdEntity.Name    = dto.Name;
            householdEntity.Address = dto.Address;

            DatabaseContext.SaveChanges();

            HouseholdDto householdDto = buildDto(householdEntity);

            return(householdDto);
        }
Beispiel #9
0
        public HouseholdDto GetById(int id)
        {
            HouseholdEntity entity = DatabaseContext.Households.Find(id);

            return(buildDto(entity));
        }