Exemple #1
0
 public ColoursController(IColourService colourService, ColourContext context,
                          ILogger <ColoursController> logger, IOptions <Settings.Email> settings)
 {
     _colourService = colourService;
     _context       = context;
     _logger        = logger;
     _settings      = settings.Value;
 }
Exemple #2
0
        public void Init()
        {
            _mockedLogger           = new Mock <ILogger <ColourService> >();
            _mockedColourRepository = new Mock <IRepository <Colour> >();

            _colourService = new ColourService(
                _mockedLogger.Object,
                _mockedColourRepository.Object);
        }
 public ColoursController(
     ILogger <ColoursController> logger,
     IMapper mapper,
     IColourService colourService,
     IPersonDetailsService personDetailsService)
 {
     _logger               = logger;
     _mapper               = mapper;
     _colourService        = colourService;
     _personDetailsService = personDetailsService;
 }
        public ColourController(IColourService ColourService, IUnitOfWork unitOfWork, IExceptionHandlingService exec)
        {
            _ColourService = ColourService;
            _unitOfWork    = unitOfWork;
            _exception     = exec;

            //Log Initialization
            LogVm.SessionId      = 0;
            LogVm.ControllerName = System.Web.HttpContext.Current.Request.RequestContext.RouteData.GetRequiredString("controller");
            LogVm.ActionName     = System.Web.HttpContext.Current.Request.RequestContext.RouteData.GetRequiredString("action");
            LogVm.User           = System.Web.HttpContext.Current.Request.RequestContext.HttpContext.User.Identity.Name;
        }
Exemple #5
0
        static void Main(string[] args)
        {
            // Create service collection.
            ServiceCollection sc = new ServiceCollection();

            // Adds wanted modules to scope.
            sc.AddScoped <IColourService, ColourService>();
            sc.AddScoped <IPersonService, PersonService>();
            sc.AddScoped <IPetService, PetService>();
            sc.AddScoped <IPetTypeService, PetTypeService>();
            sc.AddScoped <IColourRepository, ColourRepository>();
            sc.AddScoped <IPersonRepository, PersonRepository>();
            sc.AddScoped <IPetRepository, PetRepository>();
            sc.AddScoped <IPetTypeRepository, PetTypeRepository>();
            sc.AddScoped <IUserInterface, ConsoleUI>();

            // Build Service.
            ServiceProvider sp = sc.BuildServiceProvider();

            #region TestData

            IColourService cs        = sp.GetRequiredService <IColourService>();
            var            black     = cs.Add("Black");
            var            mortisCol = cs.Add("Orange");
            var            grey      = cs.Add("Grey");
            var            white     = cs.Add("White");

            IPetTypeService pts        = sp.GetRequiredService <IPetTypeService>();
            var             dog        = pts.Add("Dog");
            var             cat        = pts.Add("Cat");
            var             goat       = pts.Add("Goat");
            var             mortisType = pts.Add("Dreadnought");

            IPersonService pss         = sp.GetRequiredService <IPersonService>();
            var            mortisOwner = pss.Add("Jens", "Jensen", "Jensvej 5", 536736, "*****@*****.**");
            var            r1Owner     = pss.Add("John", "Smith", "Global Avenue 66", 66666666, "*****@*****.**");
            var            r2Owner     = pss.Add("Wonda Bonda", "Sonda", "Vegetable Street 49", 432589, "*****@*****.**");

            IPetService ps = sp.GetRequiredService <IPetService>();
            ps.Add("Mortis", new DateTime(), DateTime.Now, mortisCol, mortisType, mortisOwner, 12000000.0);
            ps.Add("Jaga", new DateTime(), DateTime.Now, grey, dog, r1Owner, 10.0);
            ps.Add("Macauley", new DateTime(), DateTime.Now, black, cat, r1Owner, 1300.0);
            ps.Add("Leray", new DateTime(), DateTime.Now, grey, cat, r1Owner, 533);
            ps.Add("Guy", new DateTime(), DateTime.Now, white, dog, r2Owner, 153.53);
            ps.Add("Fabia", new DateTime(), DateTime.Now, white, goat, r2Owner, 99333);

            #endregion

            // Gets generated User Interface to run Show() Method.
            IUserInterface ui = sp.GetRequiredService <IUserInterface>();
            ui.Show();
        }
Exemple #6
0
 public ColoursController(IColourService colourService)
 {
     _colourService = colourService;
 }
Exemple #7
0
        public ConsoleUI(IColourService colourService, IPersonService personService, IPetService petService, IPetTypeService petTypeService)
        {
            _colServ = colourService;
            _psnServ = personService;
            _petServ = petService;
            _ptServ  = petTypeService;

            main        = new Menu("Main Menu");
            colourMenu  = new Menu("Colour Menu", main);
            personMenu  = new Menu("Person Menu", main);
            petMenu     = new Menu("Pet Menu", main);
            petTypeMenu = new Menu("Pet Type Menu", main);
            petReadMenu = new Menu("Pet Read Menu", petMenu);

            #region Main
            main.SetMenu(
                new MenuItem[] {
                new MenuItem("Pet", () =>
                {
                    Console.Clear();
                    petMenu.Show();
                }),
                new MenuItem("Pet Type", () =>
                {
                    Console.Clear();
                    petTypeMenu.Show();
                }),
                new MenuItem("Person", () =>
                {
                    Console.Clear();
                    personMenu.Show();
                }),
                new MenuItem("Colour", () =>
                {
                    Console.Clear();
                    colourMenu.Show();
                })
            });
            #endregion

            #region Colour
            colourMenu.SetMenu(
                new MenuItem[] {
                new MenuItem("Create", () =>
                {
                    string description = ConsoleUtils.ReadNotEmpty("Input colour description: ");

                    try
                    {
                        Colour colour = _colServ.Add(description);
                        Console.WriteLine("Successfully added {0} to the repository!", colour.Description);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Read All", () =>
                {
                    try
                    {
                        List <Colour> colours = _colServ.GetAll();
                        if (colours.Count > 0)
                        {
                            foreach (Colour col in colours)
                            {
                                Console.WriteLine("ID: {0}, Description: {1}.", col.Id, col.Description);
                            }
                        }
                        else
                        {
                            Console.WriteLine("There are no colours stored.");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Update", () =>
                {
                    int index          = ConsoleUtils.ReadInt("Input id of colour wanted changed: ");
                    string description = ConsoleUtils.ReadNotEmpty("Input colour description: ");

                    try
                    {
                        Colour colour = _colServ.Update(index, description);
                        Console.WriteLine("Successfully updated {0}'s description to {1}!", index, colour.Description);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Delete", () =>
                {
                    int index = ConsoleUtils.ReadInt("Input id of colour wanted deleted: ");

                    try
                    {
                        Colour colour = _colServ.Delete(index);
                        Console.WriteLine("Successfully deleted {0} from the repository!", colour.Description);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                })
            });
            #endregion

            #region Person
            personMenu.SetMenu(
                new MenuItem[] {
                new MenuItem("Create", () =>
                {
                    string firstName = ConsoleUtils.ReadNotEmpty("Input first name: ");
                    string lastName  = ConsoleUtils.ReadNotEmpty("Input last name: ");
                    string address   = ConsoleUtils.ReadNotEmpty("Input address: ");
                    int phone        = ConsoleUtils.ReadInt("Input phone number: ");
                    string email     = ConsoleUtils.ReadNotEmpty("Input email: ");

                    try
                    {
                        Person person = _psnServ.Add(firstName, lastName, address, phone, email);
                        Console.WriteLine("Successfully added {0} {1} to the repository!", person.FirstName, person.LastName);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Read All", () =>
                {
                    try
                    {
                        List <Person> persons = _psnServ.GetAll();
                        if (persons.Count > 0)
                        {
                            foreach (Person psn in persons)
                            {
                                Console.WriteLine("ID: {0}, First name: {1}, Last name: {2}, address: {3}, phone: {4}, email: {5}.", psn.Id, psn.FirstName, psn.LastName, psn.Address, psn.Phone, psn.Email);
                            }
                        }
                        else
                        {
                            Console.WriteLine("There are no persons stored.");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Update", () =>
                {
                    int index        = ConsoleUtils.ReadInt("Input id of person wanted changed: ");
                    string firstName = ConsoleUtils.ReadNotEmpty("Input first name: ");
                    string lastName  = ConsoleUtils.ReadNotEmpty("Input last name: ");
                    string address   = ConsoleUtils.ReadNotEmpty("Input address: ");
                    int phone        = ConsoleUtils.ReadInt("Input phone number: ");
                    string email     = ConsoleUtils.ReadNotEmpty("Input email: ");

                    try
                    {
                        Person person = _psnServ.Update(index, firstName, lastName, address, phone, email);
                        Console.WriteLine("Successfully updated {0}'s to First name: {1}, Last name: {2}, address: {3}, phone: {4}, email: {5}!", index, person.FirstName, person.LastName, person.Address, person.Address, person.Phone, person.Email);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Delete", () =>
                {
                    int index = ConsoleUtils.ReadInt("Input id of person wanted deleted: ");

                    try
                    {
                        Person person = _psnServ.Delete(index);
                        Console.WriteLine("Successfully deleted {0} {1} from the repository!", person.FirstName, person.LastName);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                })
            });
            #endregion

            #region Pet
            petMenu.SetMenu(
                new MenuItem[] {
                new MenuItem("Create", () =>
                {
                    string name        = ConsoleUtils.ReadNotEmpty("Input name: ");
                    DateTime birthDate = ConsoleUtils.ReadDate("Input birth date: ");
                    DateTime soldDate  = ConsoleUtils.ReadDate("Input sold date: ");

                    Colour colour = ChooseColour(petMenu);
                    if (colour == null)
                    {
                        Console.WriteLine("No colours found! Create the colour before creating the pet.");
                        return;
                    }

                    PetType type = ChoosePetType(petMenu);
                    if (type == null)
                    {
                        Console.WriteLine("No pet types found! Create the pet type before creating the pet.");
                        return;
                    }

                    Person previousOwner = ChoosePerson(petMenu);
                    if (previousOwner == null)
                    {
                        Console.WriteLine("No persons found! Create the person before creating the pet.");
                        return;
                    }

                    double price = ConsoleUtils.ReadDouble("Input price: ");

                    try
                    {
                        Pet pet = _petServ.Add(name, birthDate, soldDate, colour, type, previousOwner, price);
                        Console.WriteLine("Successfully added {0} to the repository!", pet.Name);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Read", () =>
                {
                    Console.Clear();
                    petReadMenu.Show();
                }),
                new MenuItem("Update", () =>
                {
                    int index          = ConsoleUtils.ReadInt("Input id of pet wanted updated: ");
                    string name        = ConsoleUtils.ReadNotEmpty("Input name: ");
                    DateTime birthDate = ConsoleUtils.ReadDate("Input birth date: ");
                    DateTime soldDate  = ConsoleUtils.ReadDate("Input sold date: ");

                    Colour colour = ChooseColour(petMenu);
                    if (colour == null)
                    {
                        Console.WriteLine("No colours found! Create the colour before creating the pet.");
                        return;
                    }

                    PetType type = ChoosePetType(petMenu);
                    if (type == null)
                    {
                        Console.WriteLine("No pet types found! Create the pet type before creating the pet.");
                        return;
                    }

                    Person previousOwner = ChoosePerson(petMenu);
                    if (previousOwner == null)
                    {
                        Console.WriteLine("No persons found! Create the person before creating the pet.");
                        return;
                    }

                    double price = ConsoleUtils.ReadDouble("Input price: ");

                    try
                    {
                        Pet pet = _petServ.Update(index, name, birthDate, soldDate, colour, type, previousOwner, price);
                        Console.WriteLine("Successfully updated {0}'s to Name: {1}, Birth Date: {2}, Sold Date: {3}, Colour: {4}, Pet Type: {5}, Previous Owner: {6} {7}, Price {8}.", index, pet.Name, pet.BirthDate, pet.SoldDate, pet.Colour.Description, pet.Type.Type, pet.PreviousOwner.FirstName, pet.PreviousOwner.LastName, pet.Price);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Delete", () =>
                {
                    int index = ConsoleUtils.ReadInt("Input id of pet wanted deleted: ");

                    try
                    {
                        Pet pet = _petServ.Delete(index);
                        Console.WriteLine("Successfully deleted {0} from the repository!", pet.Name);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                })
            });
            #endregion

            #region Pet Type
            petTypeMenu.SetMenu(
                new MenuItem[] {
                new MenuItem("Create", () =>
                {
                    string type = ConsoleUtils.ReadNotEmpty("Input pet type: ");

                    try
                    {
                        PetType petType = _ptServ.Add(type);
                        Console.WriteLine("Successfully added {0} to the repository!", petType.Type);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Read All", () =>
                {
                    try
                    {
                        List <PetType> petTypes = _ptServ.GetAll();
                        if (petTypes.Count > 0)
                        {
                            foreach (PetType pt in petTypes)
                            {
                                Console.WriteLine("ID: {0}, Type: {1}.", pt.Id, pt.Type);
                            }
                        }
                        else
                        {
                            Console.WriteLine("There are no pet types stored.");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Update", () =>
                {
                    int index   = ConsoleUtils.ReadInt("Input id of pet type wanted changed: ");
                    string type = ConsoleUtils.ReadNotEmpty("Input pet type: ");

                    try
                    {
                        PetType petType = _ptServ.Update(index, type);
                        Console.WriteLine("Successfully updated {0}'s type to {1}!", index, petType.Type);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Delete", () =>
                {
                    int index = ConsoleUtils.ReadInt("Input id of pet type wanted deleted: ");

                    try
                    {
                        PetType petType = _ptServ.Delete(index);
                        Console.WriteLine("Successfully deleted {0} from the repository!", petType.Type);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                })
            });
            #endregion

            #region Pet Read
            petReadMenu.SetMenu(
                new MenuItem[] {
                new MenuItem("Read All", () =>
                {
                    try
                    {
                        List <Pet> pets = _petServ.GetAll();
                        if (pets.Count > 0)
                        {
                            foreach (Pet pet in pets)
                            {
                                Console.WriteLine("ID: {0}, Name: {1}, Birth Date: {2}, Sold Date: {3}, Colour: {4}, Pet Type: {5}, Previous Owner: {6} {7}, Price {8}.", pet.Id, pet.Name, pet.BirthDate, pet.SoldDate, pet.Colour.Description, pet.Type.Type, pet.PreviousOwner.FirstName, pet.PreviousOwner.LastName, pet.Price);
                            }
                        }
                        else
                        {
                            Console.WriteLine("There are no pets stored.");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Read By ID", () =>
                {
                    int index = ConsoleUtils.ReadInt("Input pet id: ");
                    try
                    {
                        Pet pet = _petServ.GetById(index);
                        if (pet != null)
                        {
                            Console.WriteLine("ID: {0}, Name: {1}, Birth Date: {2}, Sold Date: {3}, Colour: {4}, Pet Type: {5}, Previous Owner: {6} {7}, Price {8}.", pet.Id, pet.Name, pet.BirthDate, pet.SoldDate, pet.Colour.Description, pet.Type.Type, pet.PreviousOwner.FirstName, pet.PreviousOwner.LastName, pet.Price);
                        }
                        else
                        {
                            Console.WriteLine("ID was not found in repository.");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Read All Ordered By Price Ascending", () =>
                {
                    try
                    {
                        List <Pet> pets = _petServ.GetAllOrderPrice();
                        if (pets.Count > 0)
                        {
                            foreach (Pet pet in pets)
                            {
                                Console.WriteLine("ID: {0}, Name: {1}, Birth Date: {2}, Sold Date: {3}, Colour: {4}, Pet Type: {5}, Previous Owner: {6} {7}, Price {8}.", pet.Id, pet.Name, pet.BirthDate, pet.SoldDate, pet.Colour.Description, pet.Type.Type, pet.PreviousOwner.FirstName, pet.PreviousOwner.LastName, pet.Price);
                            }
                        }
                        else
                        {
                            Console.WriteLine("There are no pets stored.");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Read Five Cheapest", () =>
                {
                    try
                    {
                        List <Pet> pets = _petServ.GetFiveCheapest();
                        if (pets.Count > 0)
                        {
                            foreach (Pet pet in pets)
                            {
                                Console.WriteLine("ID: {0}, Name: {1}, Birth Date: {2}, Sold Date: {3}, Colour: {4}, Pet Type: {5}, Previous Owner: {6} {7}, Price {8}.", pet.Id, pet.Name, pet.BirthDate, pet.SoldDate, pet.Colour.Description, pet.Type.Type, pet.PreviousOwner.FirstName, pet.PreviousOwner.LastName, pet.Price);
                            }
                        }
                        else
                        {
                            Console.WriteLine("There are no pets stored.");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }),
                new MenuItem("Read By Type", () =>
                {
                    PetType type = ChoosePetType(petMenu);
                    if (type == null)
                    {
                        Console.WriteLine("No pet types found! Create the pet type before searching.");
                        return;
                    }

                    try
                    {
                        List <Pet> pets = _petServ.SearchByType(type);
                        if (pets.Count > 0)
                        {
                            foreach (Pet pet in pets)
                            {
                                Console.WriteLine("ID: {0}, Name: {1}, Birth Date: {2}, Sold Date: {3}, Colour: {4}, Pet Type: {5}, Previous Owner: {6} {7}, Price {8}.", pet.Id, pet.Name, pet.BirthDate, pet.SoldDate, pet.Colour.Description, pet.Type.Type, pet.PreviousOwner.FirstName, pet.PreviousOwner.LastName, pet.Price);
                            }
                        }
                        else
                        {
                            Console.WriteLine("There are no pets of this type.");
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message);
                    }
                })
            });
            #endregion
        }
 public ColourController(IColourService colourService)
 {
     this.colourService = colourService;
 }
 public PeopleController(IPersonService personService, IColourService colourService)
 {
     PersonService = personService;
     ColourService = colourService;
 }
 public ColourController(IColourService colourService)
 {
     this.colourService = colourService;
 }
Exemple #11
0
        static void Main(string[] args)
        {
            // Create service collection.
            ServiceCollection sc = new ServiceCollection();

            // Adds wanted modules to scope.
            sc.AddScoped <IColourService, ColourService>();
            sc.AddScoped <IPersonService, PersonService>();
            sc.AddScoped <IPetService, PetService>();
            sc.AddScoped <IPetTypeService, PetTypeService>();
            sc.AddScoped <IColourRepository, ColourDBRepository>();
            sc.AddScoped <IPersonRepository, PersonDBRepository>();
            sc.AddScoped <IPetRepository, PetDBRepository>();
            sc.AddScoped <IPetTypeRepository, PetTypeDBRepository>();
            sc.AddScoped <IUserInterface, ConsoleUI>();

            // Build Service.
            ServiceProvider sp = sc.BuildServiceProvider();

            #region TestData

            IAddressService ads     = sp.GetRequiredService <IAddressService>();
            var             jensvej = ads.Add("Jensvej", 5, null, 0, null, 6700, "Jensbjerg");
            var             global  = ads.Add("Global Avenue", 66, "b", 0, null, 3322, "Gaby");
            var             veggie  = ads.Add("Vegtable Street", 49, "V", 42, "MF", 2743, "Salatary");

            IColourService cs        = sp.GetRequiredService <IColourService>();
            var            black     = cs.Add("Black");
            var            mortisCol = cs.Add("Orange");
            var            grey      = cs.Add("Grey");
            var            white     = cs.Add("White");

            IPetTypeService pts        = sp.GetRequiredService <IPetTypeService>();
            var             dog        = pts.Add("Dog");
            var             cat        = pts.Add("Cat");
            var             goat       = pts.Add("Goat");
            var             mortisType = pts.Add("Dreadnought");

            IPersonService pss         = sp.GetRequiredService <IPersonService>();
            var            mortisOwner = pss.Add("Jens", "Jensen", jensvej, 536736, "*****@*****.**");
            var            r1Owner     = pss.Add("John", "Smith", global, 66666666, "*****@*****.**");
            var            r2Owner     = pss.Add("Wonda Bonda", "Sonda", veggie, 432589, "*****@*****.**");

            IPetService ps = sp.GetRequiredService <IPetService>();
            ps.Add(new Pet {
                Name = "Mortis", BirthDate = new DateTime(), SoldDate = new DateTime(), Colour = mortisCol, Type = mortisType, PreviousOwner = mortisOwner, Price = 12000000.0
            });
            ps.Add(new Pet {
                Name = "Jaga", BirthDate = new DateTime(), SoldDate = new DateTime(), Colour = grey, Type = dog, PreviousOwner = r1Owner, Price = 10.0
            });
            ps.Add(new Pet {
                Name = "Macauley", BirthDate = new DateTime(), SoldDate = new DateTime(), Colour = black, Type = cat, PreviousOwner = r1Owner, Price = 1300.0
            });
            ps.Add(new Pet {
                Name = "Leray", BirthDate = new DateTime(), SoldDate = new DateTime(), Colour = grey, Type = cat, PreviousOwner = r1Owner, Price = 533
            });
            ps.Add(new Pet {
                Name = "Guy", BirthDate = new DateTime(), SoldDate = new DateTime(), Colour = white, Type = dog, PreviousOwner = r2Owner, Price = 153.53
            });
            ps.Add(new Pet {
                Name = "Fabia", BirthDate = new DateTime(), SoldDate = new DateTime(), Colour = white, Type = goat, PreviousOwner = r2Owner, Price = 99333
            });

            #endregion

            // Gets generated User Interface to run Show() Method.
            IUserInterface ui = sp.GetRequiredService <IUserInterface>();
            ui.Show();
        }