public static void Delete() { try { Console.WriteLine("Please select customer to delete:"); GetList(); Console.Write("Enter ID of customer you want to delete:"); using (SalonContext salonContext = new SalonContext()) { CustomerRepository customerRepository = new CustomerRepository(salonContext); List <int> listOfIDs = customerRepository.GetIds(); string idToDelete = Console.ReadLine(); int idOfCustomer; while (!Int32.TryParse(idToDelete, out idOfCustomer) || !listOfIDs.Contains(idOfCustomer)) { Console.WriteLine($"Customer with ID {idOfCustomer} dosent found. Try again: "); idToDelete = Console.ReadLine(); } CustomerRepository customerManager = new CustomerRepository(salonContext); customerManager.Delete(idOfCustomer); Console.WriteLine($"Customer with ID {idToDelete} deleted."); } } catch (Exception ex) { Console.WriteLine("Something went wrong... Try latter"); Console.WriteLine(ex.Message); } }
public static void Add() { try { State state = new State(); Console.WriteLine("Please enter the following information:"); Console.Write("Order status: "); state.OrderStatus = Console.ReadLine(); while (string.IsNullOrWhiteSpace(state.OrderStatus)) { Console.Write("Please enter correct name of status:"); state.OrderStatus = Console.ReadLine(); } using (SalonContext salonContext = new SalonContext()) { ISalonManager <State> stateManager = new StateRepository(salonContext); State addedState = stateManager.Add(state); } Console.WriteLine($"Status {state.OrderStatus} successfully added!"); } catch (Exception ex) { Console.WriteLine("Something went wrong... Try latter"); Console.WriteLine(ex.Message); } }
public static void ChangePastEnrollmentsStatus(SalonContext context) { if (context.Enrollment.Any()) { var activeEnrols = context.Enrollment .Where(q => q.Active == true && q.Date < DateTime.Now) .AsNoTracking() .ToList(); if (activeEnrols.Count() > 0) { foreach (var activeEnrol in activeEnrols) { context.Attach(activeEnrol).State = EntityState.Modified; activeEnrol.Active = false; } try { context.SaveChanges(); } catch (DbUpdateConcurrencyException) { throw; } } } }
public static void Delete() { try { Console.WriteLine("Please select order status to delete:"); GetList(); Console.Write("Enter ID of order status you want to delete:"); using (SalonContext salonContext = new SalonContext()) { StateRepository stateRepository = new StateRepository(salonContext); List <int> listOfIDs = stateRepository.GetIds(); string idToDelete = Console.ReadLine(); int idOfState; while (!Int32.TryParse(idToDelete, out idOfState) || !listOfIDs.Contains(idOfState)) { Console.WriteLine($"Order status with ID {idOfState} dosent found. Try again: "); idToDelete = Console.ReadLine(); } ISalonManager <State> stateManager = new StateRepository(salonContext); stateManager.Delete(idOfState); Console.WriteLine($"Order status with ID {idToDelete} deleted."); } } catch (Exception ex) { Console.WriteLine("Something went wrong... Try latter"); Console.WriteLine(ex.Message); } }
public SalonUnitWorker(SalonContext context) { _context = context; Clients = new ClientRepository(_context); Workers = new WorkerRepository(_context); ChargeOfAccounts = new ChargeOfAccountRepository(_context); }
public LoginModel(UserManager <AppUser> userManager, SignInManager <AppUser> signInManager, ILogger <LoginModel> logger, SalonContext context) { _userManager = userManager; _signInManager = signInManager; _logger = logger; _context = context; }
public ActionResult DeleteAllClients() { var db = new SalonContext(); db.client.RemoveRange(db.client); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult EditStylist(int id, int stylist) { var db = new SalonContext(); Client theClient = db.client.Find(id); theClient.stylist = stylist; db.SaveChanges(); return(RedirectToAction("Show", new { id = id })); }
public IndexModel( UserManager <AppUser> userManager, SignInManager <AppUser> signInManager, SalonContext context) { _userManager = userManager; _signInManager = signInManager; _context = context; }
public ActionResult Delete(int id) { var db = new SalonContext(); var stylist = db.stylist.Find(id); db.stylist.Remove(stylist); db.SaveChanges(); return(RedirectToAction("Index")); }
public Student Get(int id) { Student student; using (var dbContext = new SalonContext()) { student = dbContext.Studens.FirstOrDefault(source => source.Id == id); } return(student); }
public IEnumerable <Student> Get() { IEnumerable <Student> lStudents; using (var dbContext = new SalonContext()) { lStudents = dbContext.Studens.ToArray(); } return(lStudents); }
public ActionResult DeleteClient(int id) { var db = new SalonContext(); var client = db.client.Find(id); int stylist = db.stylist.Find(client.stylist).id; db.client.Remove(client); db.SaveChanges(); return(RedirectToAction("Show", new { id = stylist })); }
public ActionResult New(string Name, string Description) { var db = new SalonContext(); Stylist addStylist = new Stylist { name = Name, description = Description, level = 1 }; db.stylist.Add(addStylist); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult AddStylistToSpecialty(int id, int specialtyId) { var db = new SalonContext(); Join addSpecialty = new Join { specialty_id = specialtyId, stylist_id = id }; db.join.Add(addSpecialty); db.SaveChanges(); return(RedirectToAction("Show", new { id = id })); }
public ActionResult AddSpecialty(string Name) { var db = new SalonContext(); Specialty addSpecialty = new Specialty { name = Name }; db.specialty.Add(addSpecialty); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult EditName(int id, string Name) { var db = new SalonContext(); var stylist = db.stylist.Find(id); if (Name != null) { stylist.name = Name; } db.SaveChanges(); return(RedirectToAction("Show", new { id = id })); }
public ActionResult Add(string Name, int Stylist) { var db = new SalonContext(); Random rnd = new Random(); Client addClient = new Client { name = Name, stylist = Stylist, hair = rnd.Next(10, 50) }; db.client.Add(addClient); db.SaveChanges(); return(RedirectToAction("Show", new { id = Stylist })); }
public ActionResult ReplaceScissors(int id, bool change) { var db = new SalonContext(); Stylist theStylist = db.stylist.Find(id); if (change == true) { theStylist.scissors = theStylist.drop; } theStylist.drop = 0; db.SaveChanges(); return(RedirectToAction("Show", new { id = id })); }
static void Main(string[] args) { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); IConfigurationRoot configuration = builder.Build(); var connection = configuration.GetConnectionString("SalonContext"); using (var reader = new StreamReader(@"Clients.csv")) { List <string> listOfCompleteRecords = new List <string>(); var firstLine = reader.ReadLine(); while (!reader.EndOfStream) { var record = reader.ReadLine(); while (!record.EndsWith('"')) { record += " "; record += reader.ReadLine(); } listOfCompleteRecords.Add(record); } // System.Console.WriteLine($"Number of records: {listOfThings.Count}"); foreach (var customerRecord in listOfCompleteRecords) { string[] customerProperty = customerRecord.Split(','); System.Console.Write($"{customerProperty.Length}"); if (customerProperty.Length != 22) { System.Console.WriteLine("There are less than 22 properties in the record"); } System.Console.WriteLine($"{customerRecord}"); customerProperty[0] = customerProperty[0].Replace("\"", "").Trim(); var customer = new Customer { FirstName = customerProperty[0].Split(' ')[0], LastName = customerProperty[0].Split(' ')[0].Length != customerProperty[0].Length ? customerProperty[0].Substring(customerProperty[0].Split(' ')[0].Length + 1, customerProperty[0].Length - customerProperty[0].Split(' ')[0].Length - 1) : "Unknown", PrimaryPhoneNumber = customerProperty[1].Replace("\"", "").Trim(), Notes = customerProperty[5].Replace("\"", "").Trim() }; SalonContext salonContext = new SalonContext(); var customers = salonContext.Customers.ToList(); salonContext.Customers.Add(customer); salonContext.SaveChanges(); } } System.Console.ReadLine(); }
public void GetAll_CategoriesNotEmpty_List() { //Arrange, Act Stylist addStylist = new Stylist { name = Name, description = Description, level = 1 }; db.stylist.Add(addStylist); db.SaveChanges(); int result = new SalonContext().stylist.ToList().Count; //Assert Assert.AreEqual(1, result); }
public void TestCleanup() { var optionsBuilder = new DbContextOptionsBuilder <SalonContext>(); optionsBuilder.UseMySQL("server=localhost;database=todd_aden_test;user=root;password=root;port=3306;"); using (var db = new SalonContext(optionsBuilder.Options)) { db.Stylists.RemoveRange(db.Stylists.ToArray()); db.Clients.RemoveRange(db.Clients.ToArray()); db.Specialties.RemoveRange(db.Specialties.ToArray()); db.StylistSpecialties.RemoveRange(db.StylistSpecialties.ToArray()); db.SaveChanges(); } }
public static void Update() { try { Console.WriteLine("Please select state to update:"); GetList(); Console.Write("Enter ID of state you want to update:"); using (SalonContext salonContext = new SalonContext()) { StateRepository stateRepository = new StateRepository(salonContext); List <int> listOfIDs = stateRepository.GetIds(); string idToUpdate = Console.ReadLine(); int idOfState; while (!Int32.TryParse(idToUpdate, out idOfState) || !listOfIDs.Contains(idOfState)) { Console.WriteLine($"State with ID {idOfState} dosent found. Try again: "); idToUpdate = Console.ReadLine(); } ISalonManager <State> stateManager = new StateRepository(salonContext); State selectedState = stateManager.GetSingle(idOfState); State stateToUpdate = new State(); Console.WriteLine("Enter the new name of order status:"); stateToUpdate.OrderStatus = Console.ReadLine(); while (string.IsNullOrWhiteSpace(stateToUpdate.OrderStatus)) { Console.Write("Please enter correct order status:"); stateToUpdate.OrderStatus = Console.ReadLine(); } State state = stateManager.Update(idOfState, stateToUpdate); Console.WriteLine($"Order status {state.OrderStatus} updated!"); } } catch (Exception ex) { Console.WriteLine("Something went wrong... Try latter"); Console.WriteLine(ex.Message); } }
public void PopulateAssignedTreatmentData(SalonContext context, Employee employee) { var allTreatments = context.Treatment; var employeeTreatments = new HashSet <int>( employee.TreatmentAssignments.Select(c => c.TreatmentId)); AssignedTreatmentDataList = new List <AssignedTreatmentData>(); foreach (var treatment in allTreatments) { AssignedTreatmentDataList.Add(new AssignedTreatmentData { TreatmentId = treatment.Id, Name = treatment.Name, Assigned = employeeTreatments.Contains(treatment.Id), Category = treatment.Category }); } }
public ActionResult CutHair(int id) { var db = new SalonContext(); Client client = db.client.Find(id); Stylist stylist = db.stylist.Find(client.stylist); stylist.CutHair(client.id); client = db.client.Find(id); if (client.hair <= 0) { //Client died db.client.Remove(client); stylist.GetDrop(); db.SaveChanges(); return(RedirectToAction("Replace", "Stylist", new { id = stylist.id })); } return(RedirectToAction("Show", new { id = id })); }
public static void Add() { try { Service service = new Service(); Console.WriteLine("Please enter the following information:"); Console.Write("Name of service: "); service.NameOfService = Console.ReadLine(); while (string.IsNullOrWhiteSpace(service.NameOfService)) { Console.Write("Please enter correct name of service:"); service.NameOfService = Console.ReadLine(); } Console.Write("Price: "); string price = Console.ReadLine(); decimal decPrice = 0; while (!Decimal.TryParse(price, out decPrice)) { Console.WriteLine("Incorrect value! Please enter a valid price: "); price = Console.ReadLine(); } service.Price = decPrice; using (SalonContext salonContext = new SalonContext()) { ISalonManager <Service> serviceManager = new ServiceRepository(salonContext); Service addedService = serviceManager.Add(service); } Console.WriteLine($"Service {service.NameOfService} successfully added!"); } catch (Exception ex) { Console.WriteLine("Something went wrong... Try latter"); Console.WriteLine(ex.Message); } }
public void UpdateEmployeeTreatments(SalonContext context, string[] selectedTreatments, Employee employeeToUpdate) { if (selectedTreatments == null) { employeeToUpdate.TreatmentAssignments = new List <TreatmentAssignment>(); return; } var selectedTreatmentsHS = new HashSet <string>(selectedTreatments); var employeeTreatments = new HashSet <int> (employeeToUpdate.TreatmentAssignments.Select(t => t.Treatment.Id)); foreach (var treatment in context.Treatment) { if (selectedTreatmentsHS.Contains(treatment.Id.ToString())) { if (!employeeTreatments.Contains(treatment.Id)) { employeeToUpdate.TreatmentAssignments.Add( new TreatmentAssignment { TreatmentId = treatment.Id, EmployeeId = employeeToUpdate.Id }); } } else { if (employeeTreatments.Contains(treatment.Id)) { TreatmentAssignment treatmentToRemove = employeeToUpdate.TreatmentAssignments .SingleOrDefault(i => i.TreatmentId == treatment.Id); context.Remove(treatmentToRemove); } } } }
public static void GetList() { try { using (SalonContext salonContext = new SalonContext()) { Console.WriteLine("List of states:"); Console.WriteLine("{0, 5} {1, 20} ", "ID", "Order status"); ISalonManager <State> stateManager = new StateRepository(salonContext); IEnumerable <State> listOfStates = stateManager.GetList(); foreach (SalonDAL.Models.State c in listOfStates) { Console.WriteLine("{0,5} {1,20}", c.Id, c.OrderStatus); } } } catch (Exception ex) { Console.WriteLine("Something went wrong... Try latter"); Console.WriteLine(ex.Message); } }
public static void GetList() { try { using (SalonContext salonContext = new SalonContext()) { Console.WriteLine("List of orders:"); Console.WriteLine("{0,4} {1,20} {2,50} {3,7} {4,20} {5,15}", "ID", "Customer", "Service", "Price", "Date", "Status"); OrderRepository orderManager = new OrderRepository(salonContext); IEnumerable <OrderTable> listOfOrders = orderManager.GetView(); foreach (SalonDAL.Models.OrderTable c in listOfOrders) { Console.WriteLine("{0,4} {1,20} {2,50} {3,7} {4,20} {5,15}", c.Id, c.Customer, c.Service, c.Price, c.Date, c.Status);; } } } catch (Exception ex) { Console.WriteLine("Something went wrong... Try latter"); Console.WriteLine(ex.Message); } }
public static void GetList() { try { using (SalonContext salonContext = new SalonContext()) { Console.WriteLine("List of customers:"); Console.WriteLine("{0, 5} {1, 20} {2, 20} {3, 15} {4, 30}", "ID", "Name", "Surname", "Phone number", "Email"); CustomerRepository customerManager = new CustomerRepository(salonContext); IEnumerable <Customer> listOfCustomers = customerManager.GetList(); foreach (SalonDAL.Models.Customer c in listOfCustomers) { Console.WriteLine("{0,5} {1,20} {2,20} {3,15} {4,30}", c.Id, c.FirstName, c.LastName, c.PhoneNumber, c.Email); } } } catch (Exception ex) { Console.WriteLine("Something went wrong... Try latter"); Console.WriteLine(ex.Message); } }