Пример #1
0
        public async Task <IActionResult> Get(int id)
        {
            TownDto townDto = await _townService.GetTown(id);

            if (townDto == null)
            {
                return(NotFound($"No town with id: {id}"));
            }

            return(Ok(_mapper.Map <TownWebModel>(townDto)));
        }
Пример #2
0
        //deletetown;Sofia
        public string Execute(IReadOnlyList <string> parameters)
        {
            if (parameters.Count != 1)
            {
                throw new ArgumentException(@"Please provide valid parameter: Town");
            }

            Town townToDelete = townService.GetTown(parameters[0]);
            var  sb           = new StringBuilder();

            sb.Append("Town: ");
            sb.AppendLine(townToDelete.Name);
            sb.AppendLine(" with addresses:");

            foreach (var address in townToDelete.Addresses)
            {
                if (!address.IsDeleted)
                {
                    sb.AppendLine(address.Text);
                }
            }

            this.writer.WriteLine(sb.ToString());
            this.writer.WriteLine("Do you want to delete the Town, together with the addresses? [Y/N]");

            var choice = this.reader.ReadKey();

            this.writer.WriteLine();
            while (true)
            {
                if (choice.KeyChar == 'y')
                {
                    foreach (var address in townToDelete.Addresses)
                    {
                        if (!address.IsDeleted)
                        {
                            addressSevice.Delete(townToDelete, address.Text);
                        }
                    }

                    this.townService.Delete(townToDelete.Name);

                    return($"Town {parameters[0]} was deleted");
                }
                else if (choice.KeyChar == 'n')
                {
                    return($"Town {townToDelete.Name} was not deleted");
                }
                else
                {
                    this.writer.WriteLine("Enter Valid Key [Y/N]");
                    choice = this.reader.ReadKey();
                    this.writer.WriteLine();
                }
            }
        }
Пример #3
0
        public string Execute(IReadOnlyList <string> parameters)
        {
            if (parameters.Count == 3)//Town;oldAddress;newAddress
            {
                Town    town    = townService.GetTown(parameters[0]);
                Address Address = addressSevice.EditText(town, parameters[1], parameters[2]);
                return($"Addres: {parameters[1]} in Town: {parameters[0]} was modified to Address: {parameters[2]}");
            }
            else if (parameters.Count == 4)//oldTown;oldAddress;newTown;newAddress
            {
                Town    oldTown    = townService.GetTown(parameters[0]);
                Address address    = addressSevice.EditText(oldTown, parameters[1], parameters[3]);
                Town    newTown    = townService.GetTown(parameters[2]);
                Address newAddress = addressSevice.EditTown(oldTown, parameters[3], newTown);
                return($"Addres: {parameters[1]} in Town: {parameters[0]} was modified " +
                       $"to Address: {parameters[3]} in Town: {parameters[2]}");
            }

            throw new ArgumentException(@"Please provide parameters: Town;oldAddress;newAddress or oldTown;oldAddress;newTown;newAddress");
        }
Пример #4
0
        //createaddress;Sofia;jk Hristo Smirnenski bl. 1
        public string Execute(IReadOnlyList <string> parameters)
        {
            if (parameters.Count != 2)
            {
                throw new ArgumentException(@"Please provide parameters: Town;Address");
            }
            var town = townService.GetTown(parameters[0]);

            var address = this.addressSevice.Add(town, parameters[1]);

            return($"Address {address.Text} in town {town.Name} was created.");
        }