Ejemplo n.º 1
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider serviceProvider, IApplicationSettingsRepository appSettingsRepository)
        {
            if (env.IsDevelopment())
            {
                app.UseBrowserLink();
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseSession();

            app.UseStaticFiles();

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            Task createRoles = CreateRoles(serviceProvider);

            createRoles.Wait();
            Task initializeAdmin = InitializeAdmin(serviceProvider);

            initializeAdmin.Wait();

            string rootPath = System.IO.Path.Combine(env.WebRootPath, "images\\apartment");

            var appSettings = appSettingsRepository.Get();

            if (appSettings == null)
            {
                var    allFiles          = Directory.GetFiles(rootPath);
                string imagesOrderString = "-";
                foreach (var file in allFiles)
                {
                    if (file.EndsWith("tb.jpg"))
                    {
                        continue;
                    }
                    var startIndex           = file.LastIndexOf('\\') + 1;
                    var length               = file.LastIndexOf('.') - startIndex;
                    var nameWithoutExtension = file.Substring(startIndex, length);
                    imagesOrderString += $"{nameWithoutExtension}-";
                }
                ApplicationSettings initialSettings = new ApplicationSettings(false, imagesOrderString);
                appSettingsRepository.Add(initialSettings);
            }
        }
Ejemplo n.º 2
0
        public IActionResult MoveUp(string guid)
        {
            var appSettings = _appSettingsRepository.Get();
            var imageOrder  = appSettings.Order;

            var index1 = -1;
            var index2 = imageOrder.IndexOf($"-{guid}-");

            for (int i = 0; i < index2; i++)
            {
                if (imageOrder.ElementAt(i).Equals('-'))
                {
                    index1 = i;
                }
            }

            if (index1 == -1)
            {
                return(RedirectToAction("Images"));
            }

            index1++; // Pomakni se sa - na sljedeci broj

            var toReplaceId1 = imageOrder.Substring(index1, index2 - index1);

            Debug.WriteLine($"{imageOrder} {index1} {index2} {toReplaceId1}");

            imageOrder = imageOrder.Replace($"-{guid}-", "-r-");
            imageOrder = imageOrder.Replace($"-{toReplaceId1}-", $"-{guid}-");
            imageOrder = imageOrder.Replace("-r-", $"-{toReplaceId1}-");

            appSettings.Order = imageOrder;
            _appSettingsRepository.Update(appSettings);

            return(RedirectToAction("Images"));
        }
Ejemplo n.º 3
0
        private HomeViewModel generateHomeViewModel()
        {
            string        rootPath      = System.IO.Path.Combine(_hostEnvironment.WebRootPath, "images\\apartment");
            HomeViewModel homeViewModel = new HomeViewModel();
            var           appSettings   = _appSettingsRepository.Get();

            homeViewModel.DirectReservation = appSettings.DirectReservation;
            var        imagesOrder     = appSettings.Order;
            var        imageIds        = imagesOrder.Split('-');
            List <int> imagesOrderList = new List <int>();

            foreach (var id in imageIds)
            {
                if (!String.IsNullOrEmpty(id))
                {
                    imagesOrderList.Add(int.Parse(id));
                }
            }

            homeViewModel.ImageOrder = imagesOrderList;
            return(homeViewModel);
        }