public IWorker makeWorker(string name, string position, string salary, string shiftname, string bookstoreid, string login, string password, string hiringdate_year, string hiringdate_month, string hiringdate_day, string id = "", string dehiringdate_year = "0", string dehiringdate_month = "0", string dehiringdate_day = "0") { Position p; bool shiftexists = false; WorkingHours wh = null; foreach (var shift in WorkingHours.Shifts) { if (shift.shiftname == shiftname) { wh = shift; shiftexists = true; break; } } if (!Enum.TryParse <Position>(position, out p) || !shiftexists) { throw new Exception("make worker has incorrect input position or shift"); } DateTime hiringdate = new DateTime(Convert.ToInt32(hiringdate_year), Convert.ToInt32(hiringdate_month), Convert.ToInt32(hiringdate_day)); DateTime dehiringdate = new DateTime(Convert.ToInt32(dehiringdate_year), Convert.ToInt32(dehiringdate_month), Convert.ToInt32(dehiringdate_day)); Bookstore workplace = dao.getBookstore(new Id <IBookstore>(bookstoreid)); return(new Worker(changeManager, name, p, Convert.ToDouble(salary), wh, login, password, id, hiringdate, dehiringdate, workplace)); }
public Bookstore getBookstore(Id <IBookstore> bookstoreId) { if (cachedBookstores.ContainsKey(bookstoreId)) { return(cachedBookstores[bookstoreId]); } var queryString = "SELECT * FROM BOOKSTORES WHERE bookstores.bookstore_id = " + bookstoreId.huelue; var command = new NpgsqlCommand(queryString, _sqlconnection.CreateConnection.Connection); var reader = command.ExecuteReader(); Bookstore bookstore = null; if (reader.HasRows) { var raw_address = reader["address_id"] as IDictionary <string, object>; bookstore = (Bookstore)bookstoreFactory?.makeBookstore( reader["bookstore_id"].ToString(), raw_address["city"].ToString(), raw_address["street"].ToString(), raw_address["house"].ToString(), reader["cashier_telephone"].ToString(), reader["manager_telephone"].ToString() ); } reader.Close(); cachedBookstores[bookstoreId] = bookstore; return(bookstore); }
private void AddBookStore() { var bookstore = new Bookstore { Name = _ioHelper.GetTextFromUser("Enter bookstore name"), Address = _ioHelper.GetTextFromUser("Enter bookstore address") }; _bookStoreService.AddAsync(bookstore).Wait(); Console.WriteLine("BookStore added successfully"); }
public void PrintBookStore(Bookstore bookStore) { Console.WriteLine($"{bookStore.Name}, Address: {bookStore.Address}"); }
//CREATE public void createWorker(string name, double salary, Position position, string login, string password, WorkingHours hours, DateTime hiring_date, Bookstore working_place) { foreach (var worker in cachedWorkers) { if (worker.Value.name == name && worker.Value.position.ToString() == position.ToString() && worker.Value.hiring_date.ToString() == hiring_date.ToString()) { return; } } var _name = name; var _salary = salary.ToString(); var _position = position.ToString(); var _login = login; var _password = password; var _hours = hours.shiftname; var _hiringdate = hiring_date.ToString(); var _bookstoreid = working_place.id.ToString(); var queryString = "INSERT INTO \"staff\" VALUES (DEFAULT,'" + _name + "'," + "'" + _hiringdate + "'" + ",NULL,'" + _position + "'," + _salary + ",'" + _hours + "'," + _bookstoreid + ");"; sendRequest(queryString); queryString = "SELECT employee_id FROM staff ORDER BY employee_id DESC limit 1"; var command = new NpgsqlCommand(queryString, _sqlconnection.CreateConnection.Connection); var reader = command.ExecuteReader(); var worker_id = new Id <IWorker>("-1"); if (reader.HasRows) { reader.Read(); worker_id = new Id <IWorker>(reader["employee_id"].ToString()); } else { throw new Exception("Workers db are empty"); } reader.Close(); cachedWorkers.Add(worker_id, (Worker)workerFactory.makeWorker(_name, _position, _salary, _hours, _bookstoreid, _login, _password, hiring_date.Year.ToString(), hiring_date.Month.ToString(), hiring_date.Day.ToString(), worker_id.ToString())); }
public Worker(IWorkerListener listener, string name, Position position, double salary, WorkingHours hours, string login, string password, string id, DateTime hiringdate, DateTime dehiringdate, Bookstore bookstore) { this.listener = listener; _name = new Property <string>(name, this); _position = new Property <Position>(position, this); _salary = new Property <double>(salary, this); _hours = new Property <WorkingHours>(hours, this); _login = new Property <string>(login, this); _password = new Property <string>(password, this); _id = new Property <Id <IWorker> >(new Id <IWorker>(id), this); _hiring_date = new Property <DateTime>(hiringdate, this); _dehiring_date = new Property <DateTime>(dehiringdate, this); _working_place = new Property <Bookstore>(bookstore, this); //this.listener.workerCreated(this); }