Beispiel #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, CatDbContext db)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                //db.Database.Migrate();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }
            app.UseHttpsRedirection();

            app.UseStaticFiles();

            app.UseCookiePolicy();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
            });
        }
Beispiel #2
0
 public ActionResult Index()
 {
     using (CatDbContext db = new CatDbContext())
     {
         List <Cat> cats = db.Cats.ToList();
         return(View(cats));
     }
 }
Beispiel #3
0
 public ActionResult Index()
 {
     using (var db = new CatDbContext())
     {
         var allCats = db.Cats.ToList();
         return(View(allCats));
     }
 }
Beispiel #4
0
 public ActionResult Index()
 {
     using (var db = new CatDbContext())
     {
         var model = db.Cats.ToList();
         return(View(model));
     }
 }
Beispiel #5
0
 public CatController(ICatRepository catRepo, IAdoptRepository adoptRepo, UserManager <IdentityUser> userManager, CatDbContext catContext, IWebHostEnvironment hostingEnvironment)
 {
     _catRepo            = catRepo;
     _userManager        = userManager;
     _adoptRepo          = adoptRepo;
     _catContext         = catContext;
     _hostingEnvironment = hostingEnvironment;
 }
Beispiel #6
0
 public ActionResult DeleteConfirm(int id, Cat catModel)
 {
     using (var db = new CatDbContext())
     {
         db.Cats.Remove(catModel);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
Beispiel #7
0
        public ActionResult Delete(int id)
        {
            using (var db = new CatDbContext())
            {
                Cat model = db.Cats.ToList().FirstOrDefault(x => x.Id == id);

                return(View(model));
            }
        }
Beispiel #8
0
        public CatService(CatDbContext catDbContext, IWebHostEnvironment webHostEnvironment)
        {
            _catDbContext = catDbContext;
            SeedDatabase();

            _downloadDirectoryPath = $"{webHostEnvironment.ContentRootPath}\\Downloads";
            if (!Directory.Exists(_downloadDirectoryPath))
            {
                Directory.CreateDirectory(_downloadDirectoryPath);
            }
        }
Beispiel #9
0
 public ActionResult Delete(int id)
 {
     using (var db = new CatDbContext())
     {
         Cat catDetails = db.Cats.FirstOrDefault(t => t.Id == id);
         if (catDetails == null)
         {
             RedirectToAction("Index");
         }
         return(View(catDetails));
     }
 }
Beispiel #10
0
 public ActionResult Edit(int id)
 {
     using (var db = new CatDbContext())
     {
         var catToEdit = db.Cats.FirstOrDefault(t => t.Id == id);
         if (catToEdit == null)
         {
             return(RedirectToAction("Index"));
         }
         return(View(catToEdit));
     }
 }
Beispiel #11
0
        public ActionResult DeleteConfirm(Cat catModel)
        {
            using (var db = new CatDbContext())
            {
                var catToDelete = db.Cats.FirstOrDefault(x => x.Id == catModel.Id);

                db.Cats.Remove(catToDelete);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Beispiel #12
0
        public ActionResult Delete(int id)
        {
            using (var db = new CatDbContext())
            {
                var catToDelete = db.Cats.FirstOrDefault(x => x.Id == id);
                if (catToDelete == null)
                {
                    return(RedirectToAction("Index"));
                }

                return(this.View(catToDelete));
            }
        }
Beispiel #13
0
        public ActionResult Delete(int id)
        {
            using (CatDbContext db = new CatDbContext())
            {
                Cat oldCat = db.Cats.FirstOrDefault(x => x.Id == id);
                if (oldCat == null)
                {
                    return(RedirectToAction("Index"));
                }

                return(View(oldCat));
            }
        }
Beispiel #14
0
        public ActionResult Create(Cat cat)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            using (var db = new CatDbContext())
            {
                db.Cats.Add(cat);
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Beispiel #15
0
        public ActionResult Edit(int id)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }

            using (var db = new CatDbContext())
            {
                Cat model = db.Cats.ToList().FirstOrDefault(x => x.Id == id);

                return(View(model));
            }
        }
Beispiel #16
0
        public ActionResult EditConfirm(int id, Cat catModel)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Cat"));
            }

            using (var db = new CatDbContext())
            {
                db.Cats.Update(catModel);
                db.SaveChanges();
            }

            return(RedirectToAction("Index", "Cat"));
        }
Beispiel #17
0
        public ActionResult DeleteConfirm(Cat cat)
        {
            using (CatDbContext db = new CatDbContext())
            {
                if (cat == null)
                {
                    return(RedirectToAction("Index"));
                }

                db.Cats.Remove(cat);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
Beispiel #18
0
        public ActionResult Create(Cat cat)
        {
            if (cat.Nickname == null || cat.Name == null || cat.Price == 0)
            {
                return(RedirectToAction("Create", "Cat"));
            }

            using (var db = new CatDbContext())
            {
                db.Cats.Add(cat);
                db.SaveChanges();
            }

            return(RedirectToAction("Index", "Cat"));
        }
Beispiel #19
0
 public ActionResult EditConfirm(int id, Cat catModel)
 {
     if (!ModelState.IsValid)
     {
         return(RedirectToAction("Index"));
     }
     using (var db = new CatDbContext())
     {
         var catToEdit = db.Cats.FirstOrDefault(t => t.Id == catModel.Id);
         catToEdit.Name     = catModel.Name;
         catToEdit.Nickname = catModel.Nickname;
         catToEdit.Price    = catModel.Price;
         db.SaveChanges();
     }
     return(RedirectToAction("Index"));
 }
Beispiel #20
0
        public ActionResult EditConfirm(int id, Cat cat)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Index"));
            }
            using (var db = new CatDbContext())
            {
                Cat oldCat = db.Cats.ToList().FirstOrDefault(x => x.Id == id);

                oldCat.Name     = cat.Name;
                oldCat.Nickname = cat.Nickname;
                oldCat.Price    = cat.Price;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
        }
Beispiel #21
0
        public ActionResult Delete(int id)
        {
            if (id == null)
            {
                return(RedirectToAction("Index", "Cat"));
            }

            using (var db = new CatDbContext())
            {
                var cat = db.Cats.Find(id);

                if (cat == null)
                {
                    return(RedirectToAction("Index", "Cat"));
                }

                return(View(cat));
            }
        }
        public CatDataServiceTest()
        {
            var options = new DbContextOptionsBuilder <CatDbContext>()
                          .UseInMemoryDatabase(databaseName: "CatVotes")
                          .Options;

            context = new CatDbContext(options);
            CatDbInitializer.Initialize(context);

            var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder
                .AddFilter("Microsoft", LogLevel.Warning)
                .AddFilter("System", LogLevel.Warning)
                .AddFilter("LoggingConsoleApp.Program", LogLevel.Debug);
            });

            logger = loggerFactory.CreateLogger <CatsDataService>();
        }
Beispiel #23
0
        public ActionResult Create(string name, string nickname, double price)
        {
            if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(nickname))
            {
                return(RedirectToAction("Index"));
            }

            Cat cat = new Cat
            {
                Name     = name,
                Nickname = nickname,
                Price    = price
            };

            using (var db = new CatDbContext())
            {
                db.Cats.Add(cat);
                db.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Beispiel #24
0
 public CatController(CatDbContext context)
 {
     this.context = context;
 }
Beispiel #25
0
 public UtilRepository(CatDbContext context, StackExchange.Redis.IConnectionMultiplexer connection) : base(context)
 {
     _database = connection.GetDatabase();
 }
Beispiel #26
0
 public CatRepository(CatDbContext db)
 {
     _db = db;
 }
Beispiel #27
0
 public CatsController(CatDbContext context)
 {
     _context = context;
 }
Beispiel #28
0
 public UserRepository(CatDbContext context) : base(context)
 {
 }
 public SessionDataRepository(CatDbContext context) : base(context)
 {
 }
Beispiel #30
0
 public TangRepository(CatDbContext context) : base(context)
 {
 }