コード例 #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));
            }
        }
コード例 #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);
        }
コード例 #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));
        }
コード例 #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
        }
コード例 #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));
        }
コード例 #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)));
        }
コード例 #7
0
        public async Task <IActionResult> Update([FromBody] ServiceModel data)
        {
            var dataUpdate = await _servicesService.Update(ServiceMapper.Map(data));

            return(Ok());
        }
コード例 #8
0
 public List <ApartmentModel> GetAllApartments()
 {
     return(ServiceMapper.Map <List <ApartmentModel> >(Repository.GetAll()));
 }
コード例 #9
0
        public List <ApartmentModel> GetApartmentsByBuildingId(Guid buildingId)
        {
            var apartments = Repository.Filter(b => b.BuildingId == buildingId);

            return(ServiceMapper.Map <List <ApartmentModel> >(apartments));
        }
コード例 #10
0
        public ApartmentModel GetApartmentByOwnerId(Guid ownerId)
        {
            var apartment = Repository.Filter(a => a.OwnerId == ownerId).FirstOrDefault();

            return(ServiceMapper.Map <ApartmentModel>(apartment));
        }
コード例 #11
0
        public async Task <IActionResult> AddService([FromBody] ServiceModel service)
        {
            var newService = await _servicesService.AddService(ServiceMapper.Map(service));

            return(Ok(newService));
        }
コード例 #12
0
        public async Task <Service> Get(int id)
        {
            var data = await _serviceRepository.Get(id);

            return(ServiceMapper.Map(data));
        }
コード例 #13
0
        public async Task <Service> UpdateService(Service service)
        {
            var updated = await _servicesRepository.Update(ServiceMapper.Map(service));

            return(ServiceMapper.Map(updated));
        }
コード例 #14
0
        public async Task <Service> AddService(Service service)
        {
            var addedEntity = await _servicesRepository.Add(ServiceMapper.Map(service));

            return(ServiceMapper.Map(addedEntity));
        }
コード例 #15
0
        public async Task <IActionResult> Add([FromBody] ServiceModel data)
        {
            var dataEntity = await _servicesService.Add(ServiceMapper.Map(data));

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

            return(ServiceMapper.Map <List <BuildingModel> >(buildings));
        }
コード例 #19
0
        public async Task <Service> GetService(int id)
        {
            var entidad = await _servicesRepository.Get(id);

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

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

            return(service);
        }
コード例 #24
0
 public static List <SeventyPercentClubEntry> MapToDomain(this IList <SeventyPercentClubEntryDto> dtos) => ServiceMapper.Map <List <SeventyPercentClubEntry> >(dtos);
コード例 #25
0
ファイル: SensorService.cs プロジェクト: EcaterinaM/POS
 public SensorModel GetByApartmentId(Guid id)
 {
     return(ServiceMapper.Map <SensorModel>(Repository.Filter(s => s.ApartmentId == id).FirstOrDefault()));
 }
コード例 #26
0
 public static List <SeventyPercentClubEntryDto> MapToDto(this IList <SeventyPercentClubEntry> domains) => ServiceMapper.Map <List <SeventyPercentClubEntryDto> >(domains);