Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .WriteTo.Console()
                         .WriteTo.File("logs\\log.txt", rollingInterval: RollingInterval.Day)
                         .CreateLogger();

            Log.Information("*****************************************************");
            Log.Information("Starting");

            ServiceMapper service = new ServiceMapper();

            //Replace values into class def
            Configuration cfg = new Configuration();

            try
            {
                service.DoWork(cfg);
                Log.Information("ENDs");
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Something went wrong");
            }
            finally
            {
                Log.Information("*****************************************************");
                Log.CloseAndFlush();
            }
        }
Ejemplo n.º 2
0
        public List <Service> RetrieveAllByHotel(int idHotel)
        {
            try
            {
                ServiceMapper serviceMapper = new ServiceMapper();
                var           lstResult     = SqlDao.GetInstance()
                                              .ExecuteQueryProcedure(
                    serviceMapper.GetRetriveAllByIdStatement(idHotel)
                    );

                if (lstResult.Count <= 0)
                {
                    return(default(List <Service>));
                }

                var obj = EntityObjectMapper.BuildObjects(lstResult);

                return(obj.Cast <Service>().ToList());
            }
            catch (Exception e)
            {
                ManageException(e);
            }
            return(null);
        }
Ejemplo n.º 3
0
        public static void ConfigureMapper(IMapperConfigurationExpression config)
        {
            config.CreateMap <TripCandidateModel, TripCandidate>();
            config.CreateMap <DestinationCandidateModel, DestinationCandidate>();
            config.CreateMap <PhotoSessionModel, PhotoSession>();
            config.CreateMap <HighliteTopicViewModel, HighliteTopic>();
            config.CreateMap <HighliteTopic, HighliteTopicViewModel>();
            config.CreateMap <HighliteItemViewModel, IHighliteItem>();
            config.CreateMap <IHighliteItem, HighliteItemViewModel>();

            ServiceMapper.ConfigureMapper(config);

            // to Album
            config.CreateMap <HighliteTopic, AlbumSectionViewModel>();
            config.CreateMap <Destination, AlbumSectionViewModel>();
            config.CreateMap <Location, AlbumSectionViewModel>();
            config.CreateMap <IHighliteItem, AlbumItemViewModel>();
            config.CreateMap <Photo, AlbumItemViewModel>();


            // from album service to VModel
            config.CreateMap <AlbumItem, AlbumItemViewModel>();
            config.CreateMap <AlbumItemViewModel, AlbumItem>();
            config.CreateMap <AlbumSection, AlbumSectionViewModel>();
            config.CreateMap <AlbumSectionViewModel, AlbumSection>();
            config.CreateMap <Album, AlbumViewModel>();
            config.CreateMap <AlbumViewModel, Album>();
        }
        public async Task <Dal.Entities.WareHouse> UpdateWareHouse(Dal.Entities.WareHouse warehouse)
        {
            Guard.Argument(warehouse, nameof(warehouse)).NotNull();

            await ValidateWareHouse(warehouse);

            var currentWareHouse = await GetWareHouseById(warehouse.Id);

            if (_unitOfWork.WareHouseRepository.GetAll().Any(w => w.Code.ToLower() == warehouse.Code.ToLower() &&
                                                             w.Id != warehouse.Id))
            {
                throw new ServiceException(new ErrorMessage[]
                {
                    new ErrorMessage()
                    {
                        Message = $"{warehouse.Code} is already exits"
                    }
                });
            }

            var mapper = ServiceMapper.GetMapper();

            mapper.Map(warehouse, currentWareHouse);

            await _unitOfWork.SaveChanges();

            return(currentWareHouse);
        }
Ejemplo n.º 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            //Register ServiceMapper
            ServiceMapper.ConfigureServices(services, Configuration);
        }
        public async Task <Dal.Entities.Delivery> UpdateDelivery(Dal.Entities.Delivery delivery)
        {
            var currentDelivery = await GetDeliveryById(delivery.Id);

            if (currentDelivery.DeliveryStatus != DeliveryStatus.Pending)
            {
                throw new ServiceException(new ErrorMessage[]
                {
                    new ErrorMessage()
                    {
                        Message = "Unable update the delivery"
                    }
                });
            }

            var mapper = ServiceMapper.GetMapper();

            mapper.Map(delivery, currentDelivery);

            currentDelivery.DeliveryDate = delivery.DeliveryDate.Date;
            currentDelivery.Updated      = DateTimeOffset.UtcNow;

            await _unitOfWork.SaveChanges();

            return(currentDelivery);
        }
Ejemplo n.º 7
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.º 8
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCors(options =>
            {
                options.AddPolicy("CorsPolicy",
                                  builder => builder.AllowAnyOrigin()
                                  .AllowAnyMethod()
                                  .AllowAnyHeader());
            });
            services.AddControllers();
            services.AddScoped <ICustomService, BuzzWordGenerator>();
            services.AddScoped <ICustomService, RandomDogGenerator>();
            services.AddScoped <ICustomService, CopyCatRepeater>();
            services.AddScoped <ICustomService, OpenDotaRetriever>();
            services.AddScoped <RestExecutioner>();
            services.AddScoped <IMessageProcessor, IncomingMessageProcessor>();
            services.AddHttpClient <TelegramService>();
            services.AddHttpClient <SlackService>();
            services.AddScoped <WhatsAppService>();

            // Feature Provider Library initial setup
            // services.AddFeatureProvider(Configuration);

            //
            // services.AddOptions();
            // services.Configure<ServicesSettings>(options => Configuration.GetSection("ServicesSettings").Bind(options));

            var servicesSettings = Configuration.GetSection("ServicesSettings").Get <ServicesSettings>();//Configuration.GetSection("Services").Get<Service[]>();

            ServiceMapper.Initialize(servicesSettings);
            // services.AddSingleton<ServicesSettings>(servicesSettings);
        }
Ejemplo n.º 9
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.º 10
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.º 11
0
        public void RegisterServicesMapper(IServiceCollection services)
        {
            var configExpression = ServiceMapper.GetMapperConfiguration(new string[]
            {
                "Users.Services",
                "Accounts.Services",
                "AccountsStatements.Services"
            });

            services.AddSingleton(configExpression);
            services.AddScoped <IServiceMapper, ServiceMapper>();
        }
        public async Task <Dal.Entities.Supplier> UpdateSupplier(Dal.Entities.Supplier supplier)
        {
            Guard.Argument(supplier, nameof(supplier)).NotNull();

            await ValidateSupplier(supplier);

            await using var transaction = await _unitOfWork.GetTransaction();

            try
            {
                var currentSupplier = await GetSupplierById(supplier.Id);

                supplier.TrackerCode = currentSupplier.TrackerCode;

                var mapper = ServiceMapper.GetMapper();
                mapper.Map(supplier, currentSupplier);

                await _unitOfWork.SaveChanges();

                var savedSupplier = await GetSupplierById(supplier.Id);

                await _trackerApiService.UpdateCustomerStatus(new UpdateCustomerRequest()
                {
                    Active       = supplier.Active ? "1" : "0",
                    CustomerCode = savedSupplier.TrackerCode,
                    StatusDate   = DateTime.Now,
                    StatusReason = "Update the supplier"
                });

                await transaction.CommitAsync();
            }
            catch (TrackingApiException ex)
            {
                await transaction.RollbackAsync();

                throw new ServiceException(new ErrorMessage[]
                {
                    new ErrorMessage()
                    {
                        Code    = string.Empty,
                        Message = $"Unable to create a supplier in tracker side"
                    }
                });
            }
            catch
            {
                await transaction.RollbackAsync();

                throw;
            }

            return(await GetSupplierById(supplier.Id));
        }
Ejemplo n.º 13
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.º 14
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.º 15
0
        public override void Configure(MvvmConfiguration config)
        {
            base.Configure(config);

            ServiceMapper.RegisterObjects(config.IoC);

            Mapper.Initialize(
                cfg =>
            {
                ServiceMapper.ConfigureMapper(cfg);
                ConfigureMapper(cfg);
            });
        }
Ejemplo n.º 16
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.º 17
0
        public async Task <Dal.Entities.Product> UpdateProduct(Dal.Entities.Product product)
        {
            Guard.Argument(product, nameof(Product)).NotNull();

            await ValidateProduct(product);

            var currentProduct = await GetProductById(product.Id);

            var mapper = ServiceMapper.GetMapper();

            mapper.Map(product, currentProduct);

            await _unitOfWork.SaveChanges();

            return(currentProduct);
        }
Ejemplo n.º 18
0
        public async Task <Dal.Entities.PurchaseOrder> UpdatePurchaseOrder(Dal.Entities.PurchaseOrder purchaseOrder)
        {
            Guard.Argument(purchaseOrder, nameof(purchaseOrder)).NotNull();

            await ValidatePurchaseOrder(purchaseOrder);

            var currentPurchaseOrder = await GetPurchaseOrderById(purchaseOrder.Id);

            var mapper = ServiceMapper.GetMapper();

            mapper.Map(purchaseOrder, currentPurchaseOrder);

            currentPurchaseOrder.Updated = DateTimeOffset.UtcNow;

            await _unitOfWork.SaveChanges();

            return(currentPurchaseOrder);
        }
Ejemplo n.º 19
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            JwtModel model = GetJwtSettings();

            services.AddAuthentication(options => {
                options.DefaultAuthenticateScheme = "JwtBearer";
                options.DefaultChallengeScheme    = "JwtBearer";
            })
            .AddJwtBearer("JwtBearer", jwtBearerOptions => {
                jwtBearerOptions.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(model.Key)),

                    ValidateIssuer = false,
                    ValidIssuer    = model.Issuer,

                    ValidateAudience = true,
                    ValidAudience    = model.Audience,

                    ValidateLifetime = true,
                    ClockSkew        = TimeSpan.FromMinutes(model.MinutesToExpiration)
                };
            });

            services.AddSingleton <JwtModel>(model);
            services.AddSingleton <MainDbUser>();


            RepositoryMapper repoMapper    = new RepositoryMapper();
            ServiceMapper    serviceMapper = new ServiceMapper();

            repoMapper.AddMappings(services);
            serviceMapper.AddMappings(services);


            services.AddSingleton <IConfiguration>(Configuration);
            services.AddCors();
            services.AddMvc();
        }
Ejemplo n.º 20
0
 public static List <SeventyPercentClubEntryDto> MapToDto(this IList <SeventyPercentClubEntry> domains) => ServiceMapper.Map <List <SeventyPercentClubEntryDto> >(domains);
Ejemplo n.º 21
0
 public SensorModel GetByApartmentId(Guid id)
 {
     return(ServiceMapper.Map <SensorModel>(Repository.Filter(s => s.ApartmentId == id).FirstOrDefault()));
 }
Ejemplo n.º 22
0
        public async Task <Service> Update(Service service)
        {
            var data = await _serviceRepository.Update(ServiceMapper.Map(service));

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

            return(ServiceMapper.Map(data));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> UpdateAdmin([FromBody] ServiceModel service)
        {
            var name = await _servicesService.UpdateService(ServiceMapper.Map(service));

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

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

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

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

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

            return(ServiceMapper.Map <ApartmentModel>(apartment));
        }