示例#1
0
        public IActionResult Post([FromForm] int id, [FromForm] int inc)
        {
            var p = _context.Policas.FirstOrDefault(p => p.Id == id);

            if (p == null)
            {
                return(BadRequest());
            }

            p.TrenutnoDVD += inc;
            if (p.TrenutnoDVD > p.MaxDVD || p.TrenutnoDVD < 0)
            {
                return(BadRequest());
            }
            _context.SaveChanges();
            return(Ok(p));
        }
示例#2
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, VideoKlubContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/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.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
            });

            // OVO TI GENERISE PODATKE
            // SVKI PUT KAD SE IZVRSI

            var k1 = new VideoKlubModels.VideoKlub
            {
                Name = "Video klub 1",
            };

            var k2 = new VideoKlubModels.VideoKlub
            {
                Name = "Video klub 2",
            };

            context.VideoKlubs.Add(k1);
            context.VideoKlubs.Add(k2);

            context.Policas.Add(new Polica {
                Name = "K1 Polica 11", MaxDVD = 5, TrenutnoDVD = 0, VideoKlub = k1
            });
            context.Policas.Add(new Polica {
                Name = "K1 Polica 12", MaxDVD = 6, TrenutnoDVD = 1, VideoKlub = k1
            });
            context.Policas.Add(new Polica {
                Name = "K1 Polica 13", MaxDVD = 16, TrenutnoDVD = 16, VideoKlub = k1
            });

            context.Policas.Add(new Polica {
                Name = "K2 Polica 21", MaxDVD = 5, TrenutnoDVD = 0, VideoKlub = k2
            });
            context.Policas.Add(new Polica {
                Name = "K2 Polica 22", MaxDVD = 6, TrenutnoDVD = 1, VideoKlub = k2
            });
            context.Policas.Add(new Polica {
                Name = "K2 Polica 23", MaxDVD = 16, TrenutnoDVD = 16, VideoKlub = k2
            });

            context.SaveChanges();
        }