static void Delete() { int id = 1; using (var db = new DALContext()) { db.IceCreams.Add(new IceCream { Name = "A supprimer" }); db.SaveChanges(); foreach (var iceC in db.IceCreams) { Console.WriteLine($"Avant\nName: {iceC.Name}"); } Console.WriteLine("*****"); var icetod = db.IceCreams.Where(x => x.ID == id).FirstOrDefault(); Console.WriteLine($"{icetod.ID} {icetod.Name}"); db.IceCreams.Remove(icetod); db.SaveChanges(); foreach (var iceC in db.IceCreams) { Console.WriteLine($"Après\nName: {iceC.Name}"); } } }
static async void AddIceCream() { using (var db = new DALContext()) { IceCream a = new IceCream { Name = "IKEA" }; Rating rating = new Rating { Author = "Gab", Description = "Super glace", Rate = 4 }; Rating rating2 = new Rating { Author = "Jo", Description = "Mouais", Rate = 5 }; a.Ratings.Add(rating); a.Ratings.Add(rating2); Shop shop = new Shop { Address = "Rue des Ardennes", Name = "IceCream Shop" }; shop.Supply.Add(a); db.IceCreams.Add(a); db.Shops.Add(shop); await db.SaveChangesAsync(); Console.WriteLine("Fin"); Retrieve(); Console.Read(); } }
public void CreateProduct_AddsToDatabase() { var options = new DbContextOptionsBuilder <DALContext>() .UseInMemoryDatabase(databaseName: "CreateProductAddsToDatabase") .Options; var categoryToSearch = "Fruit"; var fruit = "Strawberries"; var categorySearched = new Category { Name = categoryToSearch }; // Run the test against one instance of the context using (var context = new DALContext(options)) { var service = new ProductService(context); service.CreateProduct(new ProductDto() { Name = fruit, Description = fruit, Category = categorySearched.Name }); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new DALContext(options)) { Assert.Equal(1, context.Products.Count()); Assert.Equal(fruit, context.Products.Single().Name); } }
private async Task <bool> AddLogin(DALContext context, string password, string confirmationKey) { try { if (context.SearchForUserByEmailAddress(EmailAddress) != null) { return(false); } int RoleId = context.Roles.FirstOrDefault(x => x.Rolename == "user").RoleId; // add login var user = new Models.Account.LoginInfo() { UserId = Guid.NewGuid().ToString(), EmailAddress = EmailAddress, Password = password, FirstName = FirstName, LastName = LastName, EmailConfirmationKey = confirmationKey, EmailConfirmed = false, RoleId = RoleId, }; context.Users.Add(user); context.SaveChanges(); return(true); } catch { return(false); } }
public void CreateLogin_AddsToDatabase() { var options = new DbContextOptionsBuilder <DALContext>() .UseInMemoryDatabase(databaseName: "CreateLoginAddsToDatabase") .Options; var dateTime = new DateTime(2019, 01, 01); var dateToSearch = new Login { DateTime = dateTime }; using (var context = new DALContext(options)) { var service = new UserService(context); service.CreateLoginForUser(new UserDto() { Logins = new List <LoginDto>() { new LoginDto() { DateTime = dateToSearch.DateTime } } }); } using (var context = new DALContext(options)) { Assert.Equal(1, context.Logins.Count()); Assert.Equal(dateTime, context.Logins.Single().DateTime); } }
static void Main(string[] args) { DALContext dALContext = new DALContext(); PlaceController placeController = new PlaceController(dALContext); DistrictController districtController = new DistrictController(dALContext); placeController.AddPlace(new Place() { DistrictId = 1, PlaceTypeId = 1, ContactId = 1, Score = 3, TopLeftX = 20, TopLeftY = 20, BottomRightX = 70, BottomRightY = 70 }); /* List<Rule> rules = new List<Rule>(); * Rule rule1 = new RuleOfSize(); * rules.Add(rule1); * Place place = new Place(); * List<Boolean> listOfBooleans = new List<Boolean>(); * * foreach (Rule rule in rules) * { * rule.PassTheRule(place); * listOfBooleans.Add(rule.pass); * }*/ Console.WriteLine(districtController.ComputeDistrictRating("Ciungi")); Console.ReadKey(); }
static void Main() { DALContext.CreateTables(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new IndexForm()); }
public MainWindow() { using (var db = new DALContext()) { InitializeComponent(); BLimp mybl = new BLimp(); DALimp mydal = new DALimp(); //mydal.AddDeliveryMen(new DeliveryMen(1567, "sa", "fzeyd@kzrjh", "0658311966")); //mydal.Assignation(new Distribution(1), new DeliveryMen(1567)); // mydal.UpdateDeliveryMen2(new DeliveryMen(12345, "MALKI34", "fzeyd@kzrjh", "0658311966")); //Client a = new BE.Client { name = "harry", mail = "*****@*****.**", telephone = "0584494104", address = "3 villa fleurie", ID = 12 }; // Client b = new BE.Client { name = "ado", mail = "*****@*****.**", telephone = "0584494104", address = "3 villa fleurie", ID = 12 }; // Address a = new Address(); // Client c = new BE.Client { name = "banane", mail = "*****@*****.**", telephone = "0584494104", address = a, ID = 12 }; // int cvgv = 78; // // mybl.AddClient(c); // int step1 = 7; // int step2 = 89; // int step3 = 12; // int step4 = 23; // List<Client> mylist = mybl.GetAllClients().ToList<Client>(); // int a13 = 26; // Distribution b1 = new Distribution(78, new DateTime(2020, 09, 18), true); //// mybl.AddDistribution(b1); // mybl.Assignation2(c, new Distribution(1)); // // foreach (var item in mydal.GetAllCountry()) // // { // // Console.WriteLine(item.city); // // } // } mydal.distdone(); } }
//Добавление строки о новом пользователе в таблицу RequestsInfo. public ActionResult CreateRequest() { //Поиск id для текущего пользователя. string userId = System.Web.HttpContext.Current.User.Identity.GetUserId(); //Old option with SQLite context. //SQLiteContext context = new SQLiteContext(); //string sqlInsert = string.Format( // @"INSERT INTO RequestsInfo(UserId, amountOfQueries, registerDateTime, lastLoginDateTime) VALUES ('{0}', {1}, '{2}', '{3}');" // , userId, 0, DateTime.Now.ToString(CultureInfo.InvariantCulture), DateTime.Now.ToString(CultureInfo.InvariantCulture)); //context.ExecuteQuery(sqlInsert); //Option with DAL layer. DALContext _context = new DALContext(); RequestInfo _requestInfo = new RequestInfo() { UserId = userId, AmountOfQueries = 0 , LastLoginDateTime = DateTime.Now.ToString(CultureInfo.InvariantCulture) , RegisterDateTime = DateTime.Now.ToString(CultureInfo.InvariantCulture) }; _context.Requests.InsertOrUpdate(_requestInfo, true); _context.Requests.Save(); return(RedirectToAction("Index", "Home")); }
public HomeController(DALContext db, IMemoryCache memoryCache, SessionManager session, Services.IEmailSender emailSender) { _db = db; _memoryCache = memoryCache; _session = session; _emailSender = emailSender; }
private void Dispose(bool disposing) { if (!disposing) { return; } DisposeBusinessObject(_userBusiness); DisposeBusinessObject(_attendancesBusiness); DisposeBusinessObject(_coursesBusiness); DisposeBusinessObject(_departmentBusiness); DisposeBusinessObject(_facultyBusiness); DisposeBusinessObject(_groupBusiness); DisposeBusinessObject(_studentCourseBusiness); DisposeBusinessObject(_studentsBusiness); DisposeBusinessObject(_teachersBusiness); DisposeBusinessObject(_typesBusiness); DisposeBusinessObject(_reportsBusiness); if (_dalContext != null) { _dalContext.Dispose(); _dalContext = null; } }
public UserIntegrationTests() { var optionsBuilder = new DbContextOptionsBuilder <DALContext>(); optionsBuilder.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=MVCAgeCheckDB;Trusted_Connection=True;"); _context = new DALContext(optionsBuilder.Options); _userController = new UserController(_context); _userLoginsController = new UserLoginsController(_context); }
public void PropertiesShouldNotBeNull() { var context = new DALContext(); context.Users.Should().NotBeNull(); context.Languages.Should().NotBeNull(); context.Projects.Should().NotBeNull(); context.Phrases.Should().NotBeNull(); context.Translations.Should().NotBeNull(); context.Votes.Should().NotBeNull(); }
static void AllIC(Func <IceCream, bool> predicate) { using (var db = new DALContext()) { var chocos = db.IceCreams.Where(predicate).ToList(); var fraises = db.IceCreams.Where(x => x.Description.Contains("fraise")).ToList(); Console.WriteLine(chocos.Count); Console.WriteLine(fraises.Count); Console.Read(); } }
static void GroupeBy() { using (var db = new DALContext()) { var l = db.Shops; var n = l.GroupBy(i => i.Name); var r = from s in l group s by s.Name into grp select grp.OrderByDescending(g => g.ID).First(); } }
static async void TestUpdate() { using (var db = new DALContext()) { var oldI = await db.IceCreams.FindAsync(4); var newI = oldI; newI.Name = "IKEA 222"; db.Entry(oldI).CurrentValues.SetValues(newI); await db.SaveChangesAsync(); } }
public StatsUserControl() { InitializeComponent(); stat = new StatVM(this); using (var db = new DALContext()) { objCountryList = stat.GetAllCountry().ToList(); BindCountryDropDown(); this.combo.ItemsSource = stat.GetAllCountry().Select(m => m.city).Distinct(); } this.DataContext = stat; }
static void Retrieve() { using (var db = new DALContext()) { foreach (var ice in db.IceCreams) { foreach (var rate in ice.Ratings) { Console.WriteLine($"{rate.Author}: {rate.Description} ** {rate.Rate}"); } } } }
static void Main(string[] args) { using (var ctx = new DALContext()) { ctx.Users.Add(new User() { Name = "John", Phone = "123-132-1232", Email = "*****@*****.**", BirthDate = DateTime.Today, JoinDate = DateTime.Today, Id = 1 }); ctx.SaveChanges(); Console.ReadKey(); } }
internal async Task <ResultBundle> RegisterUser(string originalCaptcha, DALContext context, IEmailSender _emailSender, string host) { var r = Validate(originalCaptcha); // have to del session for Captcha http://www.dotnettips.info/post/1809/%d8%a7%db%8c%d8%ac%d8%a7%d8%af-%da%a9%d9%be%da%86%d8%a7%db%8c%db%8c-captcha-%d8%b3%d8%b1%db%8c%d8%b9-%d9%88-%d8%b3%d8%a7%d8%af%d9%87-%d8%af%d8%b1-asp-net-mvc-5 if (r.IsSuccessful) { var user = context.SearchForUserByEmailAddress(EmailAddress); if (user != null) { r.AddMessage("آدرس ایمیل وارد شده قبلا برای کاربر دیگری ثبت شده است. اگر رمز عبور خود را فراموش کرده اید از طریق صفحه (ورود) اقدام به بازیابی آن نمایید."); r.IsSuccessful = false; } else { string key = Guid.NewGuid().ToString(); string keyUrl = string.Format("{0}/Account/ConfirmEmailAddress/{1}", host, key); bool emailSent = await _emailSender.SendEmailConfirmationForm(EmailAddress, keyUrl); if (!emailSent) { r.AddMessage("آدرس ایمیل وارد شده معتبر نمی باشد. امکان ثبت نام با این ایمیل وجود ندارد."); r.IsSuccessful = false; } else { string hashPassword = Utils.GenerateHashPassword(Password); if (!await AddLogin(context, hashPassword, key)) { r.AddMessage("خطایی در هنگام ذخیره اطلاعات شما در دیتابیس رخ داده است لطفا مجددا تلاش کنید."); r.IsSuccessful = false; } else { // Registeration is accepted r.UserData = context.Login(EmailAddress, hashPassword); } } } } return(r); }
public void TestSignUpForEvent() { var user = new UserCtrl().CreateUser("Fornavn", "Efternavn", "*****@*****.**" + Guid.NewGuid(), "123456"); var eCtrl = new EventCtrl(); var e = eCtrl.CreateEvent("dsd", "dewdc", 23, 213.3, 21312.3, "here", DateTime.Now.AddHours(5), false, user); // Act eCtrl.SignUpForEvent(user.Email, e.Id); // Assert using (var ctx = new DALContext()) { var reg = new UserCtrl().FindByEmail(user.Email).Registrations[0]; var found = ctx.Registrations.Find(reg.Id); Assert.AreEqual(reg.Id, found.Id); } }
public static Product CreateProduct(ProductDto productDto, DALContext context) { var category = context.GetCategoryByName(productDto.Category); if (category == null) { category = new Category { Name = productDto.Category }; } return(new Product { Name = productDto.Name, Description = productDto.Description, Category = category }); }
public void CreateUserTest() { UserCtrl uCtrl = new UserCtrl(); User user = new User { Firstname = "Niklas", Lastname = "Jørgensen", Email = "*****@*****.**" + Guid.NewGuid(), // To avoid creating the same user when rerunning the test Password = "******" }; uCtrl.CreateUser(user.Firstname, user.Lastname, user.Email, user.Password); using (var ctx = new DALContext()) { User foundUser = ctx.Users.Where(u => u.Email == user.Email).FirstOrDefault(); Assert.IsNotNull(foundUser); Assert.AreEqual(user.Firstname, foundUser.Firstname); } }
static async void Update() { using (var db = new DALContext()) { var ice = db.IceCreams.First(); Console.WriteLine("Avant "); Console.WriteLine($"{ice.Name} {ice.Description}"); var newIce = ice; newIce.Description = "Une nouvelle description"; newIce.AverageRate = 4; db.Entry(ice).CurrentValues.SetValues(newIce); await db.SaveChangesAsync(); var icen = db.IceCreams.First(); Console.WriteLine($"{icen.Name} {icen.Description}"); } }
public void PopulateProductListFull(List <ProductType> pt, string subcategoryName, string selectedBrand, string selectedColour, string selectedGender, string selectedSeason, string selectedStyle) { var list = new List <string>(); if (HttpContext.Current.User.Identity.IsAuthenticated) { var userProfile = new DAL.UserProfile(); var wardrobe = new List <UserProductLinkTables>(); userProfile = new DALContext().GetUserProfile(HttpContext.Current.User.Identity.Name); if (userProfile != null) { wardrobe = new DALContext().GetProductsByUserId(userProfile.UserId); } ProductList = new List <ProductsToShow>(); foreach (var item in wardrobe) { list.Add(item.ProductName); } } foreach (var categ in pt) { if (subcategoryName != null) { foreach (var subcateg in categ.SubCategories.Where(f => f.SubCategoryName.ToUpper() == subcategoryName.ToUpper())) { FillProductsToShows(subcateg, categ, selectedBrand, selectedColour, selectedGender, selectedSeason, selectedStyle, list); } } else { foreach (var subcateg in categ.SubCategories) { FillProductsToShows(subcateg, categ, selectedBrand, selectedColour, selectedGender, selectedSeason, selectedStyle, list); } } } }
private static string GetKey(string key, DALContext context, DbCommand command) { try { if (command.Parameters[key] != null) { string[] strs = key.Split('_'); string cIndex = strs[strs.Length - 1]; int index = 0; int.TryParse(cIndex.ToString(), out index); key = key.Replace("_" + index, "") + "_" + ++index; return(GetKey(key, context, command)); } else { return(key); } } catch (IndexOutOfRangeException) { return(key); } }
public UserArtistDAL(DALContext context) : base(context) { }
public ReportsDAL(DALContext context) : base(context) { }
public UserLoginsController(DALContext context) { _userService = new UserService(context); }
public EmployeesController(DALContext context) { _context = context; }