public UnitOfWork(TestTaskContext context) { _context = context; Students = new EfRepository <Student>(_context); Groups = new EfRepository <Group>(_context); StudentGroupRelations = new EfRepository <StudentGroupRelation>(_context); }
public ActivityController(TestTaskContext db) { _eservice = new EmployeeService(db); _atservice = new ActivityTypeService(db); _aservice = new ActivityService(db); _pservice = new ProjectService(db); _rservice = new RoleService(db); }
/// <summary> /// Возвращает курс валюты по заданному коду за указанную дату /// </summary> /// <param name="charCode">Код валюты</param> /// <param name="date">Дата</param> /// <returns></returns> static decimal GetRate(string charCode, DateTime date) { using (TestTaskContext db = new TestTaskContext()) { return(db.CurrencyRates .Where(x => x.Date.Year == date.Year && x.Date.Month == date.Month && x.Date.Day == date.Day && x.Currency == charCode) .Select(x => x.Сourse) .FirstOrDefault()); } }
public DateRepositoryTest() { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.development.json", optional: false, reloadOnChange: false); IConfigurationRoot configuration = builder.Build(); var testTaskOpsBuilder = new DbContextOptionsBuilder <TestTaskContext>(); _testTaskCtx = new TestTaskContext(testTaskOpsBuilder.UseSqlServer(configuration["ConnectionStrings:TestTaskContext"]).Options); _dateRep = new DateRepository(_testTaskCtx); }
private ITaskContext GetTestContext() { var context = new TestTaskContext(); context.Tasks.Add(new Task { TaskId = 1, TaskName = "Task 1", Priority = 1, StartDate = DateTime.Today, EndDate = DateTime.Today.AddDays(7), Status = "I" }); context.Tasks.Add(new Task { TaskId = 2, TaskName = "Task 2", Priority = 2, StartDate = DateTime.Today, EndDate = DateTime.Today.AddMonths(1), Status = "I" }); context.Tasks.Add(new Task { TaskId = 3, TaskName = "Task 3", Priority = 2, StartDate = DateTime.Today, EndDate = DateTime.Today.AddMonths(1), Status = "I", ParentId = 2 }); context.Tasks.Add(new Task { TaskId = 4, TaskName = "Task 4", Priority = 3, StartDate = DateTime.Today, EndDate = DateTime.Today.AddMonths(2), Status = "I", ParentId = 2 }); return(context); }
/// <summary> /// Запрашивает курсы валют записывает их в базу и выводит в консоль /// </summary> static void GetCourse() { //Добавление нескольких тестовых записей в таблицу Curencies если таблица пустая using (TestTaskContext db = new TestTaskContext()) { if (!db.Currencies.Any()) { var currencies = new List <Currency> { new Currency { CharCode = "USD", Id = "R01235" }, new Currency { CharCode = "EUR", Id = "R01239" }, new Currency { CharCode = "JPY", Id = "R01820" } }; db.Currencies.AddRange(currencies); db.SaveChanges(); } } while (true) { var dateString = DateTime.Now.ToString("dd.MM.yyyy"); WebClient wc = new WebClient() { Encoding = Encoding.GetEncoding(1251) }; var response = wc.DownloadString($"http://www.cbr.ru/scripts/XML_daily.asp?date_req={dateString}"); var col = XDocument.Parse(response).Root; var elements = col.Elements(); using (TestTaskContext db = new TestTaskContext()) { //Удаляем курсы за текущую дату чтобы не было дублей за один день var todayCurrencyRates = db.CurrencyRates.Where(x => x.Date.Year == DateTime.Now.Year && x.Date.Month == DateTime.Now.Month && x.Date.Day == DateTime.Now.Day); db.CurrencyRates.RemoveRange(todayCurrencyRates); //Выбираем курсы только которые есть в таблице Currencies и сохраняем их в базу с текущей датой var charCodes = db.Currencies.Select(e => e.CharCode).ToList(); foreach (var item in elements) { var element = item.Element("CharCode").Value.ToString(); if (charCodes.Contains(element)) { CurrencyRate cr = new CurrencyRate(); cr.Date = DateTime.Now.Date; cr.Currency = element; cr.Сourse = decimal.Parse(item.Element("Value").Value.ToString()); db.CurrencyRates.Add(cr); } } db.SaveChanges(); Console.WriteLine("Список валют:"); foreach (var currency in db.Currencies) { Console.WriteLine($"Код: {currency.CharCode} ID: {currency.Id}"); } Console.WriteLine("Список курсов:"); foreach (var currencyRate in db.CurrencyRates) { Console.WriteLine($"Дата: {currencyRate.Date.ToString("dd.MM.yyyy")} Код: {currencyRate.Currency} Курс: {currencyRate.Сourse}"); } } Thread.Sleep(interval); } }
public StoreRepository(TestTaskContext context) { this.context = context; }
public RoleService(TestTaskContext db) { this._db = db; }
public EmployeeService(TestTaskContext db) { this._db = db; }
public CalendarController(TestTaskContext context) { _context = context; }
public EfRepository(TestTaskContext context) { DbContext = context; }
public DatesController(TestTaskContext dbContext) { _dateRep = new DateRepository(dbContext); }
public TaskController(TestTaskContext testTaskContext) { _testTaskContext = testTaskContext; }
public DetailService(TestTaskContext context) { _context = context; }
public ProductRepository(TestTaskContext context) { this.context = context; }
public ActivityService(TestTaskContext db) { this._db = db; }
public ProjectUserRoleService(TestTaskContext db) { this._db = db; }
public ProjectController(TestTaskContext _db) { _projectService = new ProjectService(_db); }