public IActionResult submitOrder(long id) { ViewData["user_role"] = HttpContext.Session.GetInt32("user_role"); ViewData["table_code"] = HttpContext.Session.GetString("table_code"); var tableId = HttpContext.Session.GetInt32("customer_table_id"); var bill = _context.Bills .FirstOrDefault(b => b.FkCustomerTables == tableId && b.IsPaid == false); var order = _context.Orders .FirstOrDefault(o => o.Id == id); var billOrders = _context.OrderDishes .Include(d => d.FkDishesNavigation) .Include(o => o.FkOrdersNavigation) .Where(dob => dob.FkOrdersNavigation.FkBills == bill.Id) .Select(s => new { id = s.FkOrders, title = s.FkDishesNavigation.Title, quantity = s.Quantity, price = Math.Round((double)(s.FkDishesNavigation.Price - (s.FkDishesNavigation.Price * (s.FkDishesNavigation.Discount / 100))) * s.Quantity, 2) }).ToList(); try { order.Submitted = true; Events events = new Events(); events.Type = 4; events.FkBills = (long)order.FkBills; _context.Add(events); _context.Update(order); _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!OrderDishesExists(order.Id)) { return(NotFound()); } else { throw; } } double amount = billOrders.Aggregate(0.0, (acc, x) => acc + x.price); TempData["amount"] = Math.Round(amount, 2); TempData["id"] = billOrders.First().id; dynamic BillModel = new ExpandoObject(); BillModel.Orders = billOrders; ViewData["message"] = "Jūsų užsakymas buvo priimtas"; return(View(_viewsPath + "ManageOrderView.cshtml", BillModel)); }
public void Initialize() { context.Database.Migrate(); if (!context.Set <Status>().Any()) { Status[] listStatus = AddStatus(); context.AddRange(listStatus); } if (!context.Set <Person>().Any()) { PersonPhysical person = new PersonPhysical(); person.FullName = "Elvis"; person.Birth = DateTime.Now; person.Document = "446.866.553-07"; context.Add(person); PersonLegal legal = new PersonLegal(); legal.FantasyName = "Solucoes Integradas El"; legal.SocialReason = "EL Solution"; legal.Document = "54.354.255/0001-81"; context.Add(person); } if (!context.Set <TransactionsType>().Any()) { TransactionsType[] list = AddTransactionsType(); context.AddRange(list); } context.SaveChanges(); }
static void Main(string[] args) { using (var db = new DataBaseContext()) { // Create Console.WriteLine("Inserting a new Persona"); db.Add(new Models.Persona { Id = 1002, Nombres = "Marco Vinicio", Identificacion = "1721481586" }); db.Add(new Models.Persona { Id = 1003, Nombres = "Sebastian Lituma", Identificacion = "1709292829" }); db.Add(new Models.Persona { Id = 1004, Nombres = "Miguel Narvaez", Identificacion = "0920282911" }); db.SaveChanges(); // Read Console.WriteLine("Querying for a blog"); var persona = db.Personas.OrderBy(b => b.Id).First(); // Update Console.WriteLine("Updating the blog and adding a post"); persona.Nombres = "Marco Antonio Ayala Lituma"; db.SaveChanges(); // Delete Console.WriteLine("Delete the blog"); db.Remove(persona); db.SaveChanges(); } }
public async Task <IActionResult> Register(RegisterViewModel registerVm) { HttpContext.Session.SetString("user_name", ""); HttpContext.Session.SetString("id", ""); if (!ModelState.IsValid) { ModelState.AddModelError("Error", "Complet all fields."); return(View(registerVm)); } var exist = await _context.Persons .SingleOrDefaultAsync(m => m.EmailAddress == registerVm.Email); if (exist != null) { ModelState.AddModelError("Error", "Email address is used."); return(View(registerVm)); } exist = await _context.Persons .SingleOrDefaultAsync(m => m.Username == registerVm.UserName); if (exist != null) { ModelState.AddModelError("Error", "Username is used."); return(View(registerVm)); } exist = await _context.Persons .SingleOrDefaultAsync(m => m.Cnp == registerVm.Cnp); if (exist != null) { ModelState.AddModelError("Error", "Cnp is used."); return(View(registerVm)); } var user = new Person { Id = new Guid(), Cnp = registerVm.Cnp, FirstName = registerVm.FirstName, LastName = registerVm.LastName, Username = registerVm.UserName, EmailAddress = registerVm.Email, Password = CryptingUtils.Encode(registerVm.Password), Gender = registerVm.Gender, Birthday = registerVm.Birthday, Role = "Patient" }; _context.Add(user); await _context.SaveChangesAsync(); MailUtils email; email = new MailUtils(user.EmailAddress, "Account Confirmation.", "Your account has been successfully created. You can login.\nA beautiful day!\nMedicore team."); email.Send(); return(RedirectToAction("Login", "Persons")); }
// HACKS JUST FOR DEMONSTRATION public async Task <IActionResult> TakeTable(long?tableId) { if (tableId == null) { return(NotFound()); } if (HttpContext.Session.GetInt32("customer_table_id") != null) { HttpContext.Session.SetInt32("user_role", 3); return(Redirect("~/Menu")); } if (HttpContext.Session.GetInt32("user_role") != (int)3) { HttpContext.Session.SetInt32("customer_table_id", Convert.ToInt32(tableId)); string joinCode = generateJoinCode(); HttpContext.Session.SetString("table_code", joinCode); var customerTable = await _context.CustomerTables.FindAsync(tableId); if (customerTable == null || customerTable.IsTaken) { return(View("~/Customer/Views/QrCodeCustomer/" + "QrCodeView.cshtml")); } customerTable.JoinCode = joinCode; customerTable.IsTaken = true; _context.Entry(customerTable).State = EntityState.Modified; var bill = new Bills(); bill.Evaluation = ""; bill.FkCustomerTables = (long)tableId; _context.Add(bill); _context.SaveChanges(); HttpContext.Session.SetInt32("bill_id", Convert.ToInt32(bill.Id)); // Send event to the waiter Events events = new Events(); events.Type = 3; events.FkBills = bill.Id; _context.Add(events); await _context.SaveChangesAsync(); } HttpContext.Session.SetInt32("user_role", 3); return(Redirect("~/Menu")); }
public void DoesCustIDEqualTestingID() {//Arrange // locally configures for testing var options = new DbContextOptionsBuilder <DataBaseContext>() .UseInMemoryDatabase(databaseName: "customerDatabase") .Options; //ACT // Declares a using disposable with new db context with options parameter using (var db = new DataBaseContext(options)) { //instantisates cust to save for saving Customer cust = new Customer(); //sets Customer first name cust.FirstName = "ThisIs"; // Sets customer last name cust.LastName = "ATest"; // sets cust id cust.CustomerID = cust.FirstName + cust.LastName; // sets cust store id cust.StoreID = 1; // add and save changes db.Add(cust); db.SaveChanges(); } /// Assert using (var db = new DataBaseContext(options)) { var custID = db.Customers.Where(cust => cust.StoreID == 1).FirstOrDefault(); Assert.Equal("ThisIsATest", custID.CustomerID); } }
public async Task <IActionResult> submitPayment([Bind("Id,DateTime,Tips,Amount,IsPaid,Evaluation,FkDiscounts,FkCustomerTables")] Bills bills) { ViewData["user_role"] = HttpContext.Session.GetInt32("user_role"); ViewData["table_code"] = HttpContext.Session.GetString("table_code"); if (ModelState.IsValid && validatePayment(bills)) { try { Events events = new Events(); events.Type = 1; events.FkBills = bills.Id; _context.Add(events); _context.Update(bills); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!BillsExists(bills.Id)) { return(NotFound()); } else { throw; } } ViewData["message"] = "Padavėjas buvo pakviestas, palaukite"; return(View(_viewsPath + "Payment.cshtml", bills)); } ViewData["message"] = "Įvyko klaida, pakvieskite padavėją"; ViewData["FkDiscounts"] = new SelectList(_context.Discounts, "Id", "DiscountCode", bills.FkDiscounts); return(View(_viewsPath + "Payment.cshtml", bills)); }
public static DataBaseContext CreateWithData() { var options = new DbContextOptionsBuilder <DataBaseContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()) .Options; var context = new DataBaseContext(options); context.Database.EnsureCreated(); var coachEmail = Email.Create("*****@*****.**"); var coach = Coach.Create("DbContextFactorylogin", "DbContextFactorypassword", "DbContextFactoryfirstName", "DbContextFactorylastName", "Qwertyqwerty", coachEmail); var runnerEmail = Email.Create("*****@*****.**"); var runner = Runner.Create("DbContextFactoryrunnerName", "DbContextFactoryrunnerLastName", runnerEmail); var trainingDetails = TraningDetails.Create("details", "comment"); var training = Training.Create(DateTime.UtcNow, trainingDetails); coach.AddRunner(runner); coach.AddTrainigForRunner(runner, training); context.Add(coach); context.Runners.Add(runner); context.Traings.Add(training); context.SaveChanges(); return(context); }
public static void GenerateGenres(DataBaseContext db) { int lvl; string genre; Genre current = null; var parents = new Stack <Genre>(); parents.Push(null); using (var fs = new FileStream($@"{resPath}/{genresFile}", FileMode.Open)) using (var reader = new StreamReader(fs)) { while (!reader.EndOfStream) { (genre, lvl) = NormalizeGenreEntry(reader.ReadLine()); if (lvl > parents.Count) { parents.Push(current); } while (lvl < parents.Count) { parents.Pop(); } current = new Genre { Title = genre, ParentGenre = parents.Peek() }; db.Add(current); db.SaveChanges(); } } }
public async Task <IActionResult> Create(User user) { string fileName = string.Empty; string path = string.Empty; var files = HttpContext.Request.Form.Files; if (files.Count > 0) { var extension = Path.GetExtension(files[0].FileName); fileName = Guid.NewGuid().ToString() + extension; path = Path.Combine(_environment.WebRootPath, "images") + "/" + fileName; using (FileStream fs = System.IO.File.Create(path)) { files[0].CopyTo(fs); fs.Flush(); } } user.Role = "User"; user.Image = fileName; if (ModelState.IsValid) { _context.Add(user); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(user)); }
public async Task <IActionResult> RegistrationUser(RegistrationModel model) { User UserLogin = await _context.Users.FirstOrDefaultAsync(u => u.Login == model.Login); if (UserLogin != null) { ModelState.AddModelError("Login", "Такой логин уже существует"); } User userEmail = await _context.Users.FirstOrDefaultAsync(u => u.Email == model.Email); if (userEmail != null) { ModelState.AddModelError("Email", "Такая почта уже зарегистрирована"); } if (ModelState.IsValid) { User UserReg = new User { Email = model.Email, Login = model.Login, Password = model.Password, RoleId = 2 }; _context.Add(UserReg); await _context.SaveChangesAsync(); return(RedirectToAction("Login", "Logining")); } return(View(model)); }
public async Task <IActionResult> Create(Product product) { string fileName = string.Empty; string path = string.Empty; var files = HttpContext.Request.Form.Files; if (files.Count > 0) { var extension = Path.GetExtension(files[0].FileName); fileName = Guid.NewGuid().ToString() + extension; path = Path.Combine(_environment.WebRootPath, "ProductImages") + "/" + fileName; using (FileStream fs = System.IO.File.Create(path)) { files[0].CopyTo(fs); fs.Flush(); } } product.Image = fileName; product.UserId = Convert.ToInt32(User.FindFirst("Id").Value); if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } //ViewData["RecipeId"] = new SelectList(_context.Recipes, "Id", "Id", step.RecipeId); //ViewData["UserId"] = new SelectList(_context.Users, "Id", "Id", step.UserId); return(RedirectToAction("Index")); }
public async Task <IActionResult> Create([FromForm] ProfileModel profileModel) { if (ModelState.IsValid) { if (profileModel.Id == 0) { profileModel.ImageName = await SaveImage(profileModel.ImageFile); _context.Add(profileModel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { if (profileModel.ImageFile != null) { DeleteImage(profileModel.ImageName); profileModel.ImageName = await SaveImage(profileModel.ImageFile); } _context.Update(profileModel); await _context.SaveChangesAsync(); } } return(Ok(profileModel)); }
public void Add(T Entitie) { using (var dataBase = new DataBaseContext(_OptionsBuilder.Options)) { dataBase.Add(Entitie); dataBase.SaveChanges(); }; }
public async Task <IActionResult> Create(RecipeUserView recipeView) { string fileName = string.Empty; string path = string.Empty; Recipe recipe = new Recipe(); recipe.Description = recipeView.RecipeDescription; recipe.Name = recipeView.RecipeName; recipe.TimeToComplete = recipeView.RecipeTimeToComplete; recipe.UserId = Convert.ToInt32(User.FindFirst("Id").Value); //recipe.Image = fileName; if (ModelState.IsValid) { _context.Add(recipe); await _context.SaveChangesAsync(); var files = HttpContext.Request.Form.Files; if (files.Count > 0) { for (int i = 0; i < files.Count; i++) { var extension = Path.GetExtension(files[i].FileName); fileName = Guid.NewGuid().ToString() + extension; path = Path.Combine(_environment.WebRootPath, "RecipeImages") + "/" + fileName; using (FileStream fs = System.IO.File.Create(path)) { files[i].CopyTo(fs); fs.Flush(); } RecipeImages recipeImages = new RecipeImages(); recipeImages.Image = fileName; recipeImages.RecipeId = recipe.Id; _context.Add(recipeImages); await _context.SaveChangesAsync(); } } return(RedirectToAction("Recipe", "Index", new { Page = 1 })); } return(View(recipe)); }
public async Task Add(ContaDespesa Entity) { ValidarConta(Entity); if (Entity.Notifications.Count == 0) { _dataBase.Add(Entity); await _dataBase.SaveChangesAsync(); } }
public async Task <IActionResult> Create([Bind("ID,Description,CreatedDate")] Module01 module01) { if (ModelState.IsValid) { _context.Add(module01); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(module01)); }
public async Task <IActionResult> Create([Bind("ID,FullName,Group,DateOfBirth")] Student student) { if (ModelState.IsValid) { _context.Add(student); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(student)); }
public async Task <IActionResult> Create([Bind("ID,Name,Type")] Product product) { if (ModelState.IsValid) { _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(product)); }
public async Task <IActionResult> Create([Bind("VS_ID,VS_DATE,VS_DESCRIPTION")] Visits visits) { if (ModelState.IsValid) { _context.Add(visits); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(visits)); }
public async Task <IActionResult> Create([Bind("UserRoleId,Name,Description")] UserRole userRole) { if (ModelState.IsValid) { _context.Add(userRole); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(userRole)); }
public async Task <IActionResult> Create([Bind("RV_ID,RV_NAME")] Rivers rivers) { if (ModelState.IsValid) { _context.Add(rivers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(rivers)); }
public async Task <IActionResult> Create([Bind("BasicInfoID,FirstName,LastName,DateOfBirth,City,Country,MobileNo,NID,Email,Status")] BasicInfo basicInfo) { if (ModelState.IsValid) { _context.Add(basicInfo); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(basicInfo)); }
public async Task <IActionResult> Create([Bind("CN_ID,CN_NAME")] Countries countries) { if (ModelState.IsValid) { _context.Add(countries); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(countries)); }
public async Task <IActionResult> Create([Bind("Name,Id,Inn,CreateDate,UpdateDate")] IndividualEntrepreneur individualEntrepreneur) { if (ModelState.IsValid) { _context.Add(individualEntrepreneur); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(individualEntrepreneur)); }
public async Task Add(SituacaoLancamentoReceita Entity) { ValidarEntity(Entity); if (Entity.Notifications.Count == 0) { _dataBase.Add(Entity); await _dataBase.SaveChangesAsync(); } }
public async Task <IActionResult> Create([Bind("ProfileID,FirstName,LastName,Address1,Address2,City,ZipCode")] Profile profile) { if (ModelState.IsValid) { _context.Add(profile); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(profile)); }
public async Task <IActionResult> Create([Bind("MainProductID,Name,SubCategoryID")] MainProduct mainProduct) { if (ModelState.IsValid) { _context.Add(mainProduct); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(mainProduct)); }
public async Task Add(LancamentosDespesa Entity) { ValidarEntity(Entity); if (Entity.Notifications.Count == 0) { _dataBase.Add(Entity); await _dataBase.SaveChangesAsync(); } }
public async Task <IActionResult> Create(Employee employee) { if (ModelState.IsValid) { _context.Add(employee); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(employee)); }