Exemplo n.º 1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();

            DataMigrations.Migrate(app);

            app.UseAuthentication();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Import(string source, IFormFile file, bool IsEquipment = true)
        {
            var data = new List <Equipment>();

            var migration = new DataMigrations();

            try {
                switch (source)
                {
                case "MacService":
                    if (file is null || file.Length == 0 || !string.Equals(file.ContentType, "application/json", StringComparison.OrdinalIgnoreCase))
                    {
                        throw new Exception("No appropriate file selected!");
                    }

                    // Used to import Macservice data
                    await migration.ImportMacServiceJson(_service, file);

                    break;

                case "Backup":

                    //Restore from .json Export
                    if (file is null || file.Length == 0 || !string.Equals(file.ContentType, "application/json", StringComparison.OrdinalIgnoreCase))
                    {
                        throw new Exception("No appropriate file selected!");
                    }

                    data = (await migration.InsertBackupJson <Equipment>(file, IsEquipment)).ToList();
                    break;

                case "Random":

                    //Random for testing
                    await migration.InsertRandomData(_service);

                    return(Json(true));

                default:

                    return(Json(false));
                }

                for (int i = 0; i < data.Count; i++)
                {
                    await _service.Create <Equipment>(data[i]);
                }
            }
            catch (Exception) {
                throw;
            }


            return(Json(true));
        }