private static void AddAward(IAwardLogic awardlogic) { try { Console.Write("Enter Title: "); var awardTitle = Console.ReadLine(); awardlogic.AddAward(new Award(awardTitle)); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine(); }
public static void Main(string[] args) { userLogic = new UserLogic(); awardLogic = new AwardLogic(); while (true) { Console.Clear(); try { Console.WriteLine("1. Add user"); Console.WriteLine("2. Remove user"); Console.WriteLine("3. Add user's award"); Console.WriteLine("4. Show list of users"); Console.WriteLine("5. Show users with awards"); Console.WriteLine("6. Add award"); Console.WriteLine("7. Show awards"); Console.WriteLine("0. Exit"); Console.WriteLine("--------------------------"); ConsoleKeyInfo entry = Console.ReadKey(intercept: true); switch (entry.Key) { case ConsoleKey.D1: { AddUser(); Console.WriteLine("User saved."); break; } case ConsoleKey.D2: { DeleteUser(); break; } case ConsoleKey.D3: { AddAwardToUser(); break; } case ConsoleKey.D4: { ShowUsers(); break; } case ConsoleKey.D5: { ShowUsersWithAwards(); break; } case ConsoleKey.D6: { AddAward(); break; } case ConsoleKey.D7: { ShowAwards(); break; } case ConsoleKey.D0: { return; } } Console.WriteLine(); Console.Write("Press any button to continue..."); Console.ReadLine(); } catch (Exception e) { Console.WriteLine(); Console.WriteLine($"Error: {e.Message}"); Console.Write("Press any button to continue..."); Console.ReadLine(); } } }
private static void Save(IAwardLogic logic) { Console.Clear(); logic.Save(); Console.Clear(); }
public AwardsController(IAwardLogic awardLogic) { this.awardLogic = awardLogic; }
public UserPictureBllModel(IUserLogic userBll, IPictureLogic pictureBll, IAwardLogic awardBll) { this.userBll = userBll; this.pictureBll = pictureBll; this.awardBll = awardBll; }
public static void Run(IUserLogic userLogic, IAwardLogic awardLogic) { for (; ;) { Console.Clear(); Console.WriteLine($"Use commands:\nMode - change data mode\nGetAllUsers - show all users\nUser - show user with current id\nDeleteUser - delete user with current id\nAddUser - add new user"); Console.WriteLine($"GetAllAwards - show all Awards\nAward - show user with current id\nDeleteAward -delete user with current id\nAddAward - add new user\nExit - quit from application"); string choose = Console.ReadLine(); if (choose == "Exit") { return; } switch (choose) { case "Mode": Console.WriteLine($"Current mode {DataMode.GetLogic("DataMode")} will changed"); DataMode.SwitchLogic("DataMode"); Console.WriteLine($"New mode {DataMode.GetLogic("DataMode")}. This mode will work after restart of application"); Console.ReadKey(); break; case "GetAllUsers": foreach (var item in userLogic.GetAll()) { Console.WriteLine(item); } Console.ReadKey(); break; case "GetAllAwards": foreach (var item in awardLogic.GetAll()) { Console.WriteLine(item); } Console.ReadKey(); break; case "User": Console.WriteLine("Enter user id"); uint.TryParse(Console.ReadLine(), out _userId); Console.WriteLine(userLogic.GetById(_userId)); if (userLogic.GetUserAwards(_userId).Any()) { Console.WriteLine("Awards:"); foreach (uint item in userLogic.GetUserAwards(_userId)) { Console.WriteLine(awardLogic.GetById(item)); } } Console.ReadKey(); break; case "Award": Console.WriteLine("Enter award id"); uint.TryParse(Console.ReadLine(), out _awardId); Console.WriteLine(awardLogic.GetById(_awardId)); Console.ReadKey(); break; case "DeleteUser": Console.WriteLine("Enter user id"); uint.TryParse(Console.ReadLine(), out _userId); if (userLogic.DeleteById(_userId)) { Console.WriteLine($"User with id = {_userId} deleted successfully!"); } else { Console.WriteLine($"Can't delete user with id = {_userId}!"); } Console.ReadKey(); break; case "DeleteAward": Console.WriteLine("Enter award id"); uint.TryParse(Console.ReadLine(), out _awardId); if (awardLogic.DeleteById(_awardId)) { Console.WriteLine($"Award with id = {_awardId} deleted successfully!"); } else { Console.WriteLine($"Can't delete award with id = {_awardId}!"); } Console.ReadKey(); break; case "AddUser": Console.WriteLine("Enter new user name"); string _newUserName = Console.ReadLine(); Console.WriteLine("Enter new user birthday"); DateTime.TryParse(Console.ReadLine(), out DateTime _userBirthday); if (userLogic.Add(new User() { Name = _newUserName, DateOfBirth = _userBirthday })) { Console.WriteLine("User added successfully!"); } else { Console.WriteLine("Can't create new user!"); } Console.ReadKey(); break; case "AddAward": Console.WriteLine("Enter new award name"); string _newAwardName = Console.ReadLine(); if (awardLogic.Add(new Award() { Name = _newAwardName })) { Console.WriteLine("Award added successfully!"); } else { Console.WriteLine("Can't create new award!"); } Console.ReadKey(); break; default: break; } } }
static AwardService() { _awardLogic = Task06.MyDB.IoC.DependencyResolver.AwardLogic; _sb = new StringBuilder(); _awards = _awardLogic.GetAll(); }
private static void ListAllAwards(IAwardLogic awardLogic) { try { foreach (var award in awardLogic.GetAllAwards()) { Console.WriteLine($"{award.Id}. Title: \"{award.Title}\""); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine(); }
static void Main(string[] args) { IUserLogic uLogic = DependencyResolver.ULogic; IAwardLogic awLogic = DependencyResolver.ALogic; bool correct = true; while (correct) { Console.WriteLine("Choose an option"); Console.WriteLine("1: Create user"); Console.WriteLine("2: Delete user"); Console.WriteLine("3: Display users"); Console.WriteLine("4: Create award"); Console.WriteLine("5: Delete award"); Console.WriteLine("6: Display all awards"); Console.WriteLine("7: To award"); Console.WriteLine("8: Display user awards"); Console.WriteLine("0: Exit"); string option = Console.ReadLine(); switch (option) { case "0": correct = false; break; case "1": Console.WriteLine("Enter name"); string name = Console.ReadLine(); Console.WriteLine("Enter Date of birth"); string dateOfBirth = Console.ReadLine(); bool success = uLogic.CreateUser(name, dateOfBirth); if (success) { Console.WriteLine("User saved successfuly"); } else { Console.WriteLine("User saving failed, pleace check data"); } break; case "2": Console.WriteLine("Enter ID"); string id = Console.ReadLine(); if (int.TryParse(id, out int numId)) { uLogic.DeleteUser(numId); } else { Console.WriteLine("ID is NaN"); } break; case "3": var users = uLogic.DisplayUsers(); foreach (var item in users) { Console.WriteLine(); Console.WriteLine($"Id = {item.Id}"); Console.WriteLine($"Name = {item.Name}"); Console.WriteLine($"DateOfBirth = {item.DateOfBirth}"); Console.WriteLine($"Age = {item.Age}"); Console.WriteLine(); } break; case "4": Console.WriteLine("Enter award name"); string awName = Console.ReadLine(); awLogic.CreateAward(awName); break; case "5": Console.WriteLine("Enter award ID"); var awDelId = Console.ReadLine(); if (int.TryParse(awDelId, out int numAwDelId)) { awLogic.DeleteAward(numAwDelId); } else { Console.WriteLine("ID is NaN"); } awLogic.DeleteAward(numAwDelId); break; case "6": var awards = awLogic.DisplayAwards(); foreach (var item in awards) { Console.WriteLine(item.Id); Console.WriteLine(item.Name); Console.WriteLine(); } break; case "7": Console.WriteLine("Enter user ID"); string usToAw = Console.ReadLine(); Console.WriteLine("Enter award ID"); string awToAw = Console.ReadLine(); if (int.TryParse(usToAw, out int usToAwNum) && int.TryParse(awToAw, out int awToAwNum)) { awLogic.Reward(usToAwNum, awToAwNum); } else { Console.WriteLine("ID is NaN"); } break; case "8": Console.WriteLine("Enter user ID"); string dispAwId = Console.ReadLine(); List <Award> result = new List <Award>(); if (int.TryParse(dispAwId, out int dispAwIdNum)) { result = awLogic.DisplayUserAwards(dispAwIdNum); } foreach (var item in result) { Console.WriteLine(item.Name); Console.WriteLine(item.Id); } break; default: Console.WriteLine("Enter correct value"); break; } } }
public static void DeleteAward(IAwardLogic awardLogic, int Id) { awardLogic.DeleteAward(Id); }
public AwardPictureBllModel(IAwardLogic awardBll, IPictureLogic pictureBll) { this.awardBll = awardBll; this.pictureBll = pictureBll; }
public AwardPresentation(IAwardLogic awardlogic) : base(awardlogic) { }
public DependencyResolves() { this.workWithUsers = new UserLogic(); this.workWithAwards = new AwardLogic(); this.workWithAwardsToUsers = new AwardToUserLogic(); }
static Program() { userLogic = new UserLogic(); awardLogic = new AwardLogic(); }
private static void DeleteAward(IAwardLogic awardLogic, int Id) { awardLogic.DeleteAward(Id); }
private static void DisplayMenu(IUserLogic userLogic, IAwardLogic awardLogic) { while (true) { Console.WriteLine("1. Add New Employee\t\t6. Add New Award"); Console.WriteLine("2. Delete Employee\t\t7. List All Awards"); Console.WriteLine("3. List All Employees"); Console.WriteLine("4. Give Award to Employee"); Console.WriteLine("5. Revoke Award"); Console.WriteLine(); Console.WriteLine("0. Exit"); Console.WriteLine(); Console.Write("Your choice: "); string choice = Console.ReadLine(); Console.WriteLine(); switch (choice) { case "1": AddUser(userLogic); break; case "2": DelUser(userLogic); break; case "3": ListAllUsers(userLogic, awardLogic); break; case "4": RewardUser(awardLogic); break; case "5": PullOffAward(awardLogic); break; case "6": AddAward(awardLogic); break; case "7": ListAllAwards(awardLogic); break; case "0": return; default: Console.WriteLine("Incorrect input!\n"); break; } } }
private static Award GetAwardById(IAwardLogic awardLogic, int Id) { return(awardLogic.GetAwardById(Id)); }
private static void ListAllUsers(IUserLogic userLogic, IAwardLogic awardLogic) { try { foreach (var user in userLogic.GetAllUsers()) { string strId = $"{user.Id}."; string strName = $" Name: \"{user.Name}\""; string strDate = $" BirthDay: \"{user.BirthDay.ToShortDateString()}\""; string strAge = $" Age: \"{userLogic.GetAge(user.BirthDay)}\""; Console.WriteLine(strId + strName + strDate + strAge); foreach (var award in awardLogic.GetAwardsByUserId(user.Id)) { Console.WriteLine($"\tHas award: \"{award.Title}\""); } Console.WriteLine(); } } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine(); }
static DependencyResolver() { CfgDto config = new CfgDto(); if (File.Exists(_path)) { var openCfgStream = File.Open(_path, FileMode.Open); XmlSerializer xCfg = new XmlSerializer(typeof(CfgDto)); config = (CfgDto)xCfg.Deserialize(openCfgStream); } else { var openCfgStream = File.Open(_path, FileMode.Create); XmlSerializer xCfg = new XmlSerializer(typeof(CfgDto)); config.UserDao = "default"; config.UserLogic = "default"; config.AwardDao = "default"; config.AwardLogic = "default"; config.WebUserDao = "default"; config.WebUserLogic = "default"; config.ImageDao = "default"; config.ImageDao = "default"; xCfg.Serialize(openCfgStream, config); openCfgStream.Close(); } switch (config.UserDao) { case "db": _uDao = _uDao ?? (_uDao = new DbDAL.UserDao()); break; default: _uDao = _uDao ?? (_uDao = new DAL.UserDao()); break; } switch (config.UserLogic) { default: _uLogic = _uLogic ?? (_uLogic = new UserLogic(_uDao)); break; } switch (config.AwardDao) { case "db": _aDao = _aDao ?? (_aDao = new DbDAL.AwardDao()); break; default: _aDao = _aDao ?? (_aDao = new DAL.AwardDao()); break; } switch (config.AwardLogic) { default: _aLogic = _aLogic ?? (_aLogic = new AwardLogic(_aDao)); break; } switch (config.WebUserDao) { default: _wuDao = _wuDao ?? (_wuDao = new DbDAL.WebUserDao()); break; } switch (config.WebUserLogic) { default: _wuLogic = _wuLogic ?? (_wuLogic = new WebUserLogic(_wuDao)); break; } switch (config.ImageDao) { default: _imDao = _imDao ?? (_imDao = new DbDAL.ImageDao()); break; } switch (config.ImageLogic) { default: _imLogic = _imLogic ?? (_imLogic = new ImageLogic(_imDao)); break; } }
private static void RewardUser(IAwardLogic logic) { try { Console.Write("Enter Id of Employee: "); int userId = Convert.ToInt32(Console.ReadLine()); Console.Write("Enter Id of Award: "); int awardId = Convert.ToInt32(Console.ReadLine()); if (!logic.PresentAward(userId, awardId)) { Console.WriteLine("Employee or Award haven't found."); } } catch (FormatException) { Console.WriteLine("Only integer numbers are possoble."); } catch (OverflowException) { Console.WriteLine("Out of range"); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine(); }
static UserService() { _userLogic = Task06.MyDB.IoC.DependencyResolver.UserLogic; _awardLogic = Task06.MyDB.IoC.DependencyResolver.AwardLogic; _sb = new StringBuilder(); }