Ejemplo n.º 1
0
        public async Task <ServiceResponse> Create(ServiceDTO newService)
        {
            var service = ServiceMapper.Map(newService);

            if (service.Name == null)
            {
                string errorMessage1 = "Service name not found.";
                Log.Error(errorMessage1);
                return(new ServiceResponse(errorMessage1));
            }
            if (service.Description == null)
            {
                string errorMessage2 = "Service description not found.";
                Log.Error(errorMessage2);
                return(new ServiceResponse(errorMessage2));
            }
            try
            {
                await _serviceRepository.Create(service);

                await _context.SaveChangesAsync();

                return(new ServiceResponse(ServiceMapper.Map(service)));
            }
            catch (Exception exception)
            {
                string errorMessage = $"An error occured when creating the item: {exception.Message}";
                return(new ServiceResponse(errorMessage));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load your modules or register your services here!
        /// </summary>
        /// <param name="kernel">The kernel.</param>
        private static void RegisterServices(IKernel kernel)
        {
            RepositoryMapper repoMapper    = new RepositoryMapper();
            ServiceMapper    serviceMapper = new ServiceMapper();

            repoMapper.Map(kernel);
            serviceMapper.Map(kernel);
        }
Ejemplo n.º 3
0
        public GetApartmentModel GetApartmentById(Guid id)
        {
            var apartment = Repository.Filter(a => a.Id == id, new [] { "Owner" }).FirstOrDefault();

            if (apartment == null)
            {
                throw new NotFoundException("Invalid apartment id");
            }

            return(ServiceMapper.Map <GetApartmentModel>(apartment));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Open account
        /// </summary>
        /// <param name="v">name</param>
        /// <param name="base">type</param>
        /// <param name="id">id</param>
        public void OpenAccount(decimal balance, decimal bonus, int id)
        {
            Account acc = new Account()
            {
                Id          = id,
                Balance     = balance,
                BonusPoints = bonus
            };

            unitOfWork.Accounts.AddAccount(ServiceMapper.Map(acc));
            ///to-do
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Withdraw money
        /// </summary>
        /// <param name="id">Id</param>
        /// <param name="money">Money</param>
        public void WithdrawAccount(int id, decimal money)
        {
            var account = ServiceMapper.Map(unitOfWork.Accounts.GetAccount(id));

            if (money <= 0 || account == null)
            {
                throw new ArgumentException();
            }
            account.Balance     -= money;
            account.BonusPoints -= BonusPoints.GetBonusPoints("gold", money);
            unitOfWork.Accounts.UpdateAccount(ServiceMapper.Map(account));
        }
Ejemplo n.º 6
0
        public async Task <ServiceResponse> GetById(int id)
        {
            var service = await _serviceRepository.GetById(id);

            if (service == null)
            {
                string errorMessage = "Service not found.";

                Log.Error(errorMessage);

                return(new ServiceResponse(errorMessage));
            }

            return(new ServiceResponse(ServiceMapper.Map(service)));
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Update([FromBody] ServiceModel data)
        {
            var dataUpdate = await _servicesService.Update(ServiceMapper.Map(data));

            return(Ok());
        }
Ejemplo n.º 8
0
 public List <ApartmentModel> GetAllApartments()
 {
     return(ServiceMapper.Map <List <ApartmentModel> >(Repository.GetAll()));
 }
Ejemplo n.º 9
0
        public List <ApartmentModel> GetApartmentsByBuildingId(Guid buildingId)
        {
            var apartments = Repository.Filter(b => b.BuildingId == buildingId);

            return(ServiceMapper.Map <List <ApartmentModel> >(apartments));
        }
Ejemplo n.º 10
0
        public ApartmentModel GetApartmentByOwnerId(Guid ownerId)
        {
            var apartment = Repository.Filter(a => a.OwnerId == ownerId).FirstOrDefault();

            return(ServiceMapper.Map <ApartmentModel>(apartment));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> AddService([FromBody] ServiceModel service)
        {
            var newService = await _servicesService.AddService(ServiceMapper.Map(service));

            return(Ok(newService));
        }
Ejemplo n.º 12
0
        public async Task <Service> Get(int id)
        {
            var data = await _serviceRepository.Get(id);

            return(ServiceMapper.Map(data));
        }
Ejemplo n.º 13
0
        public async Task <Service> UpdateService(Service service)
        {
            var updated = await _servicesRepository.Update(ServiceMapper.Map(service));

            return(ServiceMapper.Map(updated));
        }
Ejemplo n.º 14
0
        public async Task <Service> AddService(Service service)
        {
            var addedEntity = await _servicesRepository.Add(ServiceMapper.Map(service));

            return(ServiceMapper.Map(addedEntity));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Add([FromBody] ServiceModel data)
        {
            var dataEntity = await _servicesService.Add(ServiceMapper.Map(data));

            return(Ok(dataEntity));
        }
Ejemplo n.º 16
0
 public Account GetBrand(int id)
 {
     return(ServiceMapper.Map(unitOfWork.Accounts.GetAccount(id)));
 }
Ejemplo n.º 17
0
 public IEnumerable <Account> GetAllAccounts()
 {
     return(ServiceMapper.Map(unitOfWork.Accounts.GetAll()));
 }
Ejemplo n.º 18
0
        public List <BuildingModel> GetBuildingsByOwnerId(Guid ownerId)
        {
            var buildings = Repository.Filter(b => b.OwnerId == ownerId);

            return(ServiceMapper.Map <List <BuildingModel> >(buildings));
        }
Ejemplo n.º 19
0
        public async Task <Service> GetService(int id)
        {
            var entidad = await _servicesRepository.Get(id);

            return(ServiceMapper.Map(entidad));
        }
Ejemplo n.º 20
0
 public static SeventyPercentClubEntry MapToDomain(this SeventyPercentClubEntryDto dto) => ServiceMapper.Map <SeventyPercentClubEntry>(dto);
Ejemplo n.º 21
0
        public async Task <IActionResult> UpdateAdmin([FromBody] ServiceModel service)
        {
            var name = await _servicesService.UpdateService(ServiceMapper.Map(service));

            return(Ok(name));
        }
Ejemplo n.º 22
0
 public static SeventyPercentClubEntryDto MapToDto(this SeventyPercentClubEntry domain) => ServiceMapper.Map <SeventyPercentClubEntryDto>(domain);
Ejemplo n.º 23
0
        public async Task <Service> Update(Service service)
        {
            var data = await _serviceRepository.Update(ServiceMapper.Map(service));

            return(service);
        }
Ejemplo n.º 24
0
 public static List <SeventyPercentClubEntry> MapToDomain(this IList <SeventyPercentClubEntryDto> dtos) => ServiceMapper.Map <List <SeventyPercentClubEntry> >(dtos);
Ejemplo n.º 25
0
 public SensorModel GetByApartmentId(Guid id)
 {
     return(ServiceMapper.Map <SensorModel>(Repository.Filter(s => s.ApartmentId == id).FirstOrDefault()));
 }
Ejemplo n.º 26
0
 public static List <SeventyPercentClubEntryDto> MapToDto(this IList <SeventyPercentClubEntry> domains) => ServiceMapper.Map <List <SeventyPercentClubEntryDto> >(domains);