public async Task <CityDomainModel> GetByIdAsync(int id) { var city = await _citiesRepository.GetByIdAsync(id); if (city == null) { return(null); } CityDomainModel cityModel = new CityDomainModel { Id = city.Id, Name = city.Name, CinemasList = new List <CinemaDomainModel>() }; foreach (var cinema in city.Cinemas) { CinemaDomainModel cinemaModel = new CinemaDomainModel { Id = cinema.Id, CityId = city.Id, Name = cinema.Name }; cityModel.CinemasList.Add(cinemaModel); } return(cityModel); }
/// <summary> /// პიროვნების დამტება /// </summary> /// <param name="personModel"></param> /// <returns></returns> public async Task <Result> AddPerson(PersonModel personModel) { var personPhoneNumber = new List <PersonPhoneNumbers>(); if (!personModel.PersonPhoneNumbers.IsNullOrEmpty()) { personModel.PersonPhoneNumbers.ForEach(f => personPhoneNumber.Add( new PersonPhoneNumbers { PhoneNumber = f.PhoneNumber, PhoneTypeId = (int)f.PhoneTypeId, DateCreated = DateTime.Now })); } if (personModel.CityId != null) { var city = await citiesRepository.GetByIdAsync(personModel.CityId.Value); if (city == null) { return(new Result(false, 11, ValidationMassages.CityNotFound)); } } var personEntity = new Persons { FirstName = personModel.FirstName, LastName = personModel.LastName, PersonalNumber = personModel.PersonalNumber, BirthDate = personModel.BirthDate, CityId = personModel.CityId, GenderId = personModel.GenderId, PersonPhoneNumbers = personPhoneNumber, DateCreated = DateTime.Now }; var result = await personRepository.InsertAsync(personEntity); return(result); }
public async Task <CinemaDomainModel> CreateCinemaAsync(CinemaDomainModel cinemaDomainModel, int numOfSeats, int numOfRows, string auditoriumName) { var city = await _citiesRepository.GetByIdAsync(cinemaDomainModel.CityId); if (city == null) { return(null); } var cinemas = await _cinemasRepository.GetAll(); var cinemasInSameCity = cinemas.Where(c => c.CityId == cinemaDomainModel.CityId); foreach (var cin in cinemasInSameCity) { if (cin.Name == cinemaDomainModel.Name) { return(null); } } Data.Cinema newCinema = new Data.Cinema { Name = cinemaDomainModel.Name, CityId = cinemaDomainModel.CityId }; newCinema.Auditoriums = new List <Auditorium>(); Auditorium auditorium = new Auditorium { AuditName = auditoriumName }; auditorium.Seats = new List <Seat>(); for (int j = 1; j <= numOfRows; j++) { for (int k = 1; k <= numOfSeats; k++) { Seat seat = new Seat { Row = j, Number = k }; auditorium.Seats.Add(seat); } } newCinema.Auditoriums.Add(auditorium); Data.Cinema insertedCinema = _cinemasRepository.Insert(newCinema); if (insertedCinema == null) { return(null); } _cinemasRepository.Save(); if (insertedCinema == null) { return(null); } CinemaDomainModel cinemaModel = new CinemaDomainModel { Id = insertedCinema.Id, Name = insertedCinema.Name, CityId = insertedCinema.CityId, AuditoriumsList = new List <AuditoriumDomainModel>() }; foreach (var auditoriumInserted in insertedCinema.Auditoriums) { AuditoriumDomainModel modelAuditorium = new AuditoriumDomainModel { Id = auditoriumInserted.Id, CinemaId = insertedCinema.Id, Name = auditoriumInserted.AuditName, SeatsList = new List <SeatDomainModel>() }; foreach (var seat in auditoriumInserted.Seats) { modelAuditorium.SeatsList.Add(new SeatDomainModel { Id = seat.Id, AuditoriumId = auditoriumInserted.Id, Number = seat.Number, Row = seat.Row }); } cinemaModel.AuditoriumsList.Add(modelAuditorium); } return(cinemaModel); }