コード例 #1
0
 public List <RatingType> GetRatingTypes()
 {
     using (var context = new RatingContext())
     {
         return(new List <RatingType>(context.RatingTypes));
     }
 }
コード例 #2
0
 public AccountController(UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager, SignInManager <IdentityUser> signInManager, RatingContext db, IHostEnvironment environment)
 {
     _userManager   = userManager;
     _roleManager   = roleManager;
     _signInManager = signInManager;
     _db            = db;
     _environment   = environment;
 }
コード例 #3
0
 public InstitutionsController(UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager, RatingContext db, IHostEnvironment environment, CreateFile createFile)
 {
     _userManager = userManager;
     _roleManager = roleManager;
     _db          = db;
     _environment = environment;
     _createFile  = createFile;
 }
コード例 #4
0
ファイル: RatingRepository.cs プロジェクト: Yassin02/Catmash
        /// <summary>
        /// Get a cat by passing its Id
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static Cat GetCat(string id)
        {
            log.Info(String.Format("In : GetCat : id = {0}", id));

            Cat cat = new Cat();

            using (RatingContext context = new RatingContext())
            {
                cat = context.Cats.Where(c => c.Id == id).FirstOrDefault();
            }

            log.Info("Out : GetCat");

            return(cat);
        }
コード例 #5
0
ファイル: RatingRepository.cs プロジェクト: Yassin02/Catmash
        /// <summary>
        /// Get the list of the cats
        /// </summary>
        /// <returns></returns>
        public static List <Cat> GetCats()
        {
            log.Info("In : GetCats");

            List <Cat> cats = new List <Cat>();

            using (RatingContext context = new RatingContext())
            {
                cats = context.Cats.ToList();
            }

            log.Info("Out : GetCats");

            return(cats);
        }
コード例 #6
0
ファイル: RatingRepository.cs プロジェクト: Yassin02/Catmash
        /// <summary>
        /// Get a list of the cats by a descending order based on the score
        /// </summary>
        /// <returns></returns>
        public static List <Cat> GetCatsByOrder()
        {
            log.Info("In : GetCatsByOrder");

            List <Cat> cats = new List <Cat>();

            using (RatingContext context = new RatingContext())
            {
                cats = context.Cats.OrderByDescending(c => c.Score).ToList();
            }

            log.Info("Out : GetCatsByOrder");

            return(cats);
        }
コード例 #7
0
ファイル: DbContextTests.cs プロジェクト: schletz/Pos5xhif
        public void DbCreationTest()
        {
            var options = new DbContextOptionsBuilder()
                          .UseSqlite("Data Source=Rating.db")
                          .Options;

            using (var db = new RatingContext(options))
            {
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();
                db.Import("data.sql");
                //db.Seed();
                Assert.True(true);
            }
        }
コード例 #8
0
ファイル: RatingRepository.cs プロジェクト: Yassin02/Catmash
        /// <summary>
        /// Update a cat by passing its Id and the new score
        /// </summary>
        /// <param name="id"></param>
        /// <param name="score"></param>
        public static void UpdateCat(string id, int score)
        {
            log.Info(String.Format("In : UpdateCat : id = {0} ; score = {1}", id, score));

            using (RatingContext context = new RatingContext())
            {
                var record = context.Cats.SingleOrDefault(c => c.Id == id);
                if (record != null)
                {
                    record.Score = score;
                    context.SaveChanges();
                }
            }

            log.Info("Out : UpdateCat");
        }
コード例 #9
0
 public AccountController(
     UserManager <ApplicationUser> userManager,
     SignInManager <ApplicationUser> signInManager,
     IOptions <IdentityCookieOptions> identityCookieOptions,
     IEmailSender emailSender,
     ISmsSender smsSender,
     ILoggerFactory loggerFactory,
     IHostingEnvironment env,
     RatingContext context)
 {
     _userManager          = userManager;
     _signInManager        = signInManager;
     _externalCookieScheme = identityCookieOptions.Value.ExternalCookieAuthenticationScheme;
     _emailSender          = emailSender;
     _smsSender            = smsSender;
     _logger     = loggerFactory.CreateLogger <AccountController>();
     _hostingEnv = env;     //Bpoirier: for upload
     _context    = context; //BPoirier: for database
 }
コード例 #10
0
ファイル: Program.cs プロジェクト: schletz/Pos5xhif
        public static void Main(string[] args)
        {
            Process currentProcess = Process.GetCurrentProcess();

            Console.WriteLine($"PROCESS ID: {currentProcess.Id}");

            var options = new DbContextOptionsBuilder()
                          .UseSqlite("Data Source=Rating.db")
                          .Options;

            using (var db = new RatingContext(options))
            {
                db.Database.EnsureDeleted();
                db.Database.EnsureCreated();
                db.Import("data.sql");
                //db.Seed();
            }

            CreateHostBuilder(args).Build().Run();
        }
コード例 #11
0
ファイル: Program.cs プロジェクト: schletz/Pos4xhif
 static void SeedDb()
 {
     using (RatingContext db = new RatingContext())
     {
         db.School_Rating.RemoveRange(db.School_Rating.Where(sr => sr.SR_User_School <= 9999));
         db.User.RemoveRange(db.User.Where(u => u.U_School <= 9999));
         db.School.RemoveRange(db.School.Where(s => s.S_Nr <= 9999));
         db.SaveChanges();
     }
     using (RatingContext db = new RatingContext())
     {
         db.School.Add(new School {
             S_Nr = 9998, S_Name = "Testschule 1"
         });
         db.School.Add(new School {
             S_Nr = 9999, S_Name = "Testschule 2"
         });
         var users = Enumerable.Range(0, 3).Select(i => new User()
         {
             U_School  = 9999,
             U_Phonenr = "0999" + i
         }).ToArray();
         db.User.AddRange(users);
         db.School_Rating.Add(new School_Rating
         {
             SR_Date            = DateTime.Now.Date.AddDays(-1),
             SR_User_Navigation = users[0],
             SR_Value           = 5
         });
         db.School_Rating.Add(new School_Rating
         {
             SR_Date            = DateTime.Now.Date.AddDays(0),
             SR_User_Navigation = users[1],
             SR_Value           = 5
         });
         db.SaveChanges();
     }
 }
コード例 #12
0
        public RatingController(RatingContext ratingContext, MovieContext movieContext, UserContext userContext)
        {
            _ratingContext = ratingContext;
            _movieContext  = movieContext;
            _userContext   = userContext;

            if (!_ratingContext.Ratings.Any())
            {
                _ratingContext.Ratings.Add(new Rating {
                    MovieId = 1, Score = 3, UserId = 1
                });
                _ratingContext.Ratings.Add(new Rating {
                    MovieId = 2, Score = 2, UserId = 2
                });
                _ratingContext.Ratings.Add(new Rating {
                    MovieId = 3, Score = 1, UserId = 1
                });
                _ratingContext.Ratings.Add(new Rating {
                    MovieId = 4, Score = 4, UserId = 2
                });
                _ratingContext.SaveChanges();
            }
        }
コード例 #13
0
        public MovieController(RatingContext ratingContext, MovieContext movieContext, UserContext userContext)
        {
            _movieContext  = movieContext;
            _ratingContext = ratingContext;
            _userContext   = userContext;

            if (_movieContext.Movies.Count() == 0)
            {
                _movieContext.Movies.Add(new Movie {
                    Title = "Home Alone", Genre = Genre.Comedy, RunningTime = 123, YearOfRelease = 1990
                });
                _movieContext.Movies.Add(new Movie {
                    Title = "Die Hard", Genre = Genre.Action, RunningTime = 153, YearOfRelease = 1991
                });
                _movieContext.Movies.Add(new Movie {
                    Title = "Superman", Genre = Genre.SciFi, RunningTime = 223, YearOfRelease = 2006
                });
                _movieContext.Movies.Add(new Movie {
                    Title = "Batman", Genre = Genre.Any, RunningTime = 233, YearOfRelease = 2001
                });
                _movieContext.SaveChanges();
            }
        }
コード例 #14
0
 public ValidationController(RatingContext db, UserManager <IdentityUser> userManager, SignInManager <IdentityUser> signInManager)
 {
     _db            = db;
     _userManager   = userManager;
     _signInManager = signInManager;
 }
コード例 #15
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, RatingContext ratingContext)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            DbInitializer.Initialize(ratingContext, true);

            app.UseMvc();

            app.UseSwagger()
            .UseSwaggerUI(c =>
            {
                c.SwaggerEndpoint("/swagger/v1/swagger.json", "Rating.API V1");
            });
        }
コード例 #16
0
 public MainPageController(UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager, RatingContext db)
 {
     _userManager = userManager;
     _roleManager = roleManager;
     _db          = db;
 }
コード例 #17
0
 public ViewerDataAccess(RatingContext context, IMapper mapper)
 {
     this.Context = context;
     Mapper       = mapper;
 }
コード例 #18
0
 public RatingProvider(RatingContext _dbContext)
 {
     this._dbContext = _dbContext;
 }
コード例 #19
0
ファイル: TestController.cs プロジェクト: schletz/Pos5xhif
 public TestController(RatingService service, RatingContext db)
 {
     _service = service;
     _db      = db;
 }
コード例 #20
0
        private readonly UserManager <ApplicationUser> _userManager;//BPoirier

        public CustomerController(RatingContext context, UserManager <ApplicationUser> userManager)
        {
            _context     = context;
            _userManager = userManager;
        }
コード例 #21
0
 public CriticDataAccess(RatingContext context, IMapper mapper)
 {
     this.Context = context;
     Mapper       = mapper;
 }
コード例 #22
0
 public TradeController(RatingContext context)
 {
     _context = context;
 }
コード例 #23
0
 public SchoolratingController(RatingContext context)
 {
     _db = context;
 }
コード例 #24
0
 public RatingsController(RatingContext context)
 {
     _context = context;
 }
コード例 #25
0
ファイル: Program.cs プロジェクト: schletz/Pos4xhif
        static async Task MainAsync()
        {
            int    score   = 0;
            string baseUrl = "http://localhost:5000/api";

            SeedDb();
            Console.Write("MUSTERTEST: GET api/schoolrating/test ");
            await AssertTrueAsync(async() =>
            {
                IEnumerable <SchoolDto> result = await SendAsync <IEnumerable <SchoolDto> >(
                    HttpMethod.Get,
                    $"{baseUrl}/schoolrating/test",
                    null);
                return(result.Any(r => r.Nr == 9999));
            });

            // *************************************************************************************
            Console.Write("GET /api/schoolrating ");
            score += await AssertTrueAsync(async() =>
            {
                IEnumerable <SchoolDto> result = await SendAsync <IEnumerable <SchoolDto> >(
                    HttpMethod.Get,
                    $"{baseUrl}/schoolrating",
                    null);
                return(result.Where(r => r.Nr == 9999 && r.AvgRating == 5).Count() == 1);
            });

            // *************************************************************************************
            Console.Write("POST /api/register ");
            score += await AssertTrueAsync(async() =>
            {
                UserDto result = await SendAsync <UserDto>(
                    HttpMethod.Post,
                    $"{baseUrl}/register", new UserDto
                {
                    PhoneNr = "09994",
                    School  = 9999
                });
                using (RatingContext db = new RatingContext())
                {
                    return(db.User.FirstOrDefault(u =>
                                                  u.U_School == result.School &&
                                                  u.U_Phonenr == result.PhoneNr) != null);
                }
            });

            // *************************************************************************************
            Console.Write("POST /api/register liefert HTTP 400 bei existierendem User? ");
            score += await AssertTrueAsync(async() =>
            {
                try
                {
                    UserDto result = await SendAsync <UserDto>(
                        HttpMethod.Post,
                        $"{baseUrl}/register", new UserDto
                    {
                        PhoneNr = "09991",
                        School  = 9999
                    });
                }
                catch (HttpException e) when(e.Status == 400)
                {
                    return(true);
                }
                return(false);
            });


            // *************************************************************************************
            Console.Write("POST /api/schoolrating ");
            score += await AssertTrueAsync(async() =>
            {
                RatingDto result = await SendAsync <RatingDto>(
                    HttpMethod.Post,
                    $"{baseUrl}/schoolrating", new RatingDto
                {
                    School  = 9999,
                    PhoneNr = "09992",
                    Value   = 1
                });
                using (RatingContext db = new RatingContext())
                {
                    return(db.School_Rating.Find(result.Id) != null);
                }
            });

            // *************************************************************************************
            Console.Write("POST /api/schoolrating liefert HTTP 400, wenn der User die Schule schon bewertet hat? ");
            score += await AssertTrueAsync(async() =>
            {
                try
                {
                    RatingDto result = await SendAsync <RatingDto>(
                        HttpMethod.Post,
                        $"{baseUrl}/schoolrating", new RatingDto
                    {
                        School  = 9999,
                        PhoneNr = "09991",
                        Value   = 1
                    });
                }
                catch (HttpException e) when(e.Status == 400)
                {
                    return(true);
                }
                return(false);
            });

            // *************************************************************************************
            Console.Write("PUT /api/schoolrating/(ratingId) ");
            score += await AssertTrueAsync(async() =>
            {
                long ratingId = 0;
                using (RatingContext db = new RatingContext())
                {
                    ratingId = db.School_Rating.First(sr => sr.SR_User_Phonenr == "09990").SR_ID;
                }
                RatingDto result = await SendAsync <RatingDto>(
                    HttpMethod.Put,
                    $"{baseUrl}/schoolrating/{ratingId}", new RatingDto
                {
                    Value = 2
                });
                using (RatingContext db = new RatingContext())
                {
                    return(db.School_Rating.Find(ratingId).SR_Value == 2);
                }
            });

            // *************************************************************************************
            Console.Write("PUT /api/schoolrating/(ratingId) liefert HTTP 400, wenn der User eine Bewertung des aktuellen Tages ändern will? ");
            score += await AssertTrueAsync(async() =>
            {
                long ratingId = 0;
                using (RatingContext db = new RatingContext())
                {
                    ratingId = db.School_Rating.First(sr => sr.SR_User_Phonenr == "09991").SR_ID;
                }
                try
                {
                    RatingDto result = await SendAsync <RatingDto>(
                        HttpMethod.Put,
                        $"{baseUrl}/schoolrating/{ratingId}", new RatingDto
                    {
                        Value = 2
                    });
                }
                catch (HttpException e) when(e.Status == 400)
                {
                    return(true);
                }
                return(false);
            });

            // *************************************************************************************
            Console.Write("DELETE /api/schoolrating/(ratingId) ");
            score += await AssertTrueAsync(async() =>
            {
                long ratingId = 0;
                using (RatingContext db = new RatingContext())
                {
                    ratingId = db.School_Rating.First(sr => sr.SR_User_Phonenr == "09990").SR_ID;
                }
                await SendAsync(HttpMethod.Delete, $"{baseUrl}/schoolrating/{ratingId}", null);
                using (RatingContext db = new RatingContext())
                {
                    return(db.School_Rating.Find(ratingId) == null);
                }
            });

            // *************************************************************************************
            double percent = score / 8.0;
            int    note    =
                percent > 0.875 ? 1 :
                percent > 0.75 ? 2 :
                percent > 0.625 ? 3 :
                percent > 0.5 ? 4 : 5;

            Console.WriteLine($"{score} von 8 Punkten erreicht. Note: {note}.");
            Console.ReadLine();
        }
コード例 #26
0
 public RatingService(ILogger <RatingService> logger, RatingContext ratingContext)
 {
     this.logger        = logger;
     this.ratingContext = ratingContext;
 }
コード例 #27
0
 public RatingService(RatingContext db)
 {
     _db = db;
 }
コード例 #28
0
        private Microsoft.AspNetCore.Hosting.IHostingEnvironment _hostingEnv; //Bpoirier: for upload

        public ContractorController(RatingContext context, IHostingEnvironment hostingEnv)
        {
            _context    = context;
            _hostingEnv = hostingEnv;
        }