/// <summary> /// Add /Update City /// </summary> public City SaveCity(City city) { City dbVersion = cityRepository.Find(city.CityId); //Code Duplication Check if (cityRepository.DoesCityCodeExists(city)) { throw new CaresException(Resources.GeographicalHierarchy.City.CityCodeDuplicationError); } if (dbVersion != null) { UpdateCityPropertie(city, dbVersion); cityRepository.Update(dbVersion); } else { dbVersion = new City(); SetCityProperties(city, dbVersion); cityRepository.Add(dbVersion); } regionRepository.SaveChanges(); // To Load the proprties return(cityRepository.LoadCityWithDetail(dbVersion.CityId)); }
public async Task <Result <CityModel, Error> > CreateCity(CreateCityModel cityModel) { var city = await _cityRepository.GetByName(cityModel.Name); if (city != null) { return(Result.Failure <CityModel, Error>(ErrorsList.ExistingCity)); } var userId = Guid.Parse(_accessor.HttpContext.User.Claims.First(c => c.Type == "userId").Value); var user = await _userRepository.GetById(userId); var userType = await _userTypeRepository.GetByName("Admin"); if (user.UserTypeId != userType.Id) { return(Result.Failure <CityModel, Error>(ErrorsList.UnauthorizedUser)); } var newCity = new City(cityModel.Name); await _cityRepository.Add(newCity); await _cityRepository.SaveChanges(); return(Result.Success <CityModel, Error>(_mapper.Map <CityModel>(newCity))); }
public void AddCity(AddCityViewModel model) { var checkCity = _cityRepository.GetAll(x => x.CityName == model.CityName && x.DeleteDate == null).FirstOrDefault(); if (checkCity == null) { var city = new City(); city.CityName = model.CityName; city.CreateDate = DateTime.Now; var user = _userService.GetUser(); city.UserId = user.UserId; var entity = _cityRepository.Add(city); if (entity != null) { try { _cityRepository.SaveChanges(); } catch (Exception ex) { var errorMessage = ex.Message; throw; } } } }
public async Task <ActionResult <Venue> > Post(string activityName, Venue venue) { try { var existingVenue = await repository.GetVenueAsync(venue.Name); if (existingVenue != null) { return(BadRequest("Venue name already in use!")); } repository.Add(venue); if (await repository.SaveChangesAsync()) { var newVenueSaved = await repository.GetVenueAsync(venue.Name); var activity = await repository.GetActivityAsync(activityName); if (activity == null) { return(BadRequest("Activity name does not exist!")); } ActivityVenue activityVenue = new ActivityVenue() { ActivityId = activity.ActivityId, VenueId = newVenueSaved.VenueId, Activity = activity, Venue = newVenueSaved }; activity.ActivityVenues.Add(activityVenue); newVenueSaved.ActivityVenues.Add(activityVenue); if (await repository.SaveChangesAsync()) { var url = linkGenerator.GetPathByAction(HttpContext, "Get", values: new { cityName = "mtl", activityName = activity.Name, name = newVenueSaved.Name }); return(Created(url, newVenueSaved)); } else { return(BadRequest("Failed to save new venue!")); } } return(BadRequest("Failed to save new venue!")); } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } }
public GeneralResponse AddCity(AddCityRequest request) { GeneralResponse response = new GeneralResponse(); try { City city = new City(); city.ID = Guid.NewGuid(); city.CreateDate = PersianDateTime.Now; city.CreateEmployee = _employeeRepository.FindBy(request.CreateEmployeeID); city.CityName = request.CityName; city.RowVersion = 1; //Validation if (city.GetBrokenRules().Count() > 0) { foreach (BusinessRule businessRule in city.GetBrokenRules()) { response.ErrorMessages.Add(businessRule.Rule); } return(response); } _cityRepository.Add(city); _uow.Commit(); } catch (Exception ex) { response.ErrorMessages.Add(ex.Message); if (ex.InnerException != null) { response.ErrorMessages.Add(ex.InnerException.Message); } } return(response); }
public async Task <IActionResult> AddCity([FromBody] CityDTO city) { if (!ModelState.IsValid) { return(BadRequest("Invalid input")); } City newCity = new City() { name = city.name, country = city.country, attractions = city.attractions }; if (_cityRepository.CheckIfExists(newCity)) { return(Conflict("City already exists")); } bool created = await _cityRepository.Add(newCity); if (created) { return(Created("", newCity)); } return(Conflict()); }
public ActionResult Add() { City city = (City)TempData["getCity"]; _serviceDb.Add(city); return(RedirectToAction("Contact")); }
public bool Add(City item) { if (_cityRepository.GetSingleById(item.Id) == null && !_cityRepository.Exists(m => m.Name.Trim().ToUpper() == item.Name.ToUpper())) { item.CreatedDate = DateTime.Now; _cityRepository.Add(item); } return(true); }
async Task IStartDataService.AddCities() { City city = new City(); city.Name = "Хургада"; city.Country = await _countryRepository.Get(1); await _cityRepository.Add(city); }
public ActionResult Create(CityCreateOrUpdateViewModel model) { if (ModelState.IsValid) { var cityModel = new City() { Title = model.Title, Show = model.Show, StateId = model.StateId }; _cityRepository.Add(cityModel); _cityRepository.Complete(); return(RedirectToAction("List")); } return(RedirectToAction("Create")); }
async Task <CityDTO> IService <CityDTO, int> .Add(CityDTO entity) { City city = (await _cityRepository.Get(prop => prop.Name == entity.Name)).FirstOrDefault(); if (city == null) { city = await _cityRepository.Add(_mapper.Map <CityDTO, City>(entity)); } return(_mapper.Map <City, CityDTO>(city)); }
public IActionResult Create([FromBody] City city) { if (city == null) { return(BadRequest()); } _cityRepository.Add(city); return(CreatedAtRoute("GetCity", new { id = city.Id }, city)); }
public IActionResult AddCity(CityWithoutPointsOfInterestDto city) { var cityToAdd = _mapper.Map <City>(city); var res = _cityRepository.Add(cityToAdd); if (res) { return(StatusCode(201, "Success")); } return(StatusCode(500, "Error while saving")); }
public void Add(City city) { try { _cityRepository.Add(city); _logger.LogInformation("New City was created!"); } catch (Exception exception) { _logger.LogError("An error occurred while creating the City" + " | " + exception); throw; } }
public bool CreateCity(CityRowViewModel model) { if (_cityRepository.Get(x => x.Deleted == false && x.Name.Equals(model.Name)) == null) { var city = new City(); city.Name = model.Name; city.TimeZoneId = model.TimeZoneId; _cityRepository.Add(city); _unitOfWork.CommitChanges(); return(true); } return(false); }
public IActionResult AddCity(JsonElement request) { var countryId = request.GetProperty("countryId").GetInt32(); var cityName = request.GetProperty("cityName").GetString(); var country = _countryRepository.GetCountry(countryId); if (country == null) { return(BadRequest("Country Not Found")); } _cityRepository.Add(new City { Name = cityName, CountryId = countryId, Country = country }); return(Ok("Successful")); }
public void add(city city) { if (String.IsNullOrWhiteSpace(city.city1)) { throw new InvalidInputException("Must include city name"); } try { var existingCity = findByNameAndCountryId(city.city1, city.countryId); throw new DataIntegrityViolationException("City already exists"); }catch (NotFoundException e) { _repository.Add(city); } }
public void Add(CityViewModel cityViewModel) { var request = _restClient.GetMethod(cityViewModel.Name); var group = request.list.GroupBy(c => c.dt_txt.Date); var media = group.Select(c => new { Data = c.Key, MediaWeather = c.Sum(a => a.main.temp) / c.Count() }); var entity = _mapper.Map <City>(cityViewModel); media.ToList().ForEach(a => entity.AddWeather(new Weather(a.Data, a.MediaWeather))); _cityRepository.Add(entity); _cityRepository.SaveChanges(); }
public async Task <CreateCityResult> Handle(CreateCity request) { var cityId = Guid.NewGuid(); _cityRepository.Add(new CityEntity { Id = cityId, Name = request.City.Name }); await _unitOfWork.SaveChangesAsync(); return(new CreateCityResult { CityId = cityId }); }
public bool Add(CityCreateModel entity) { City city = new City { Name = entity.Name, Postcode = entity.Postcode, CreatedBy = entity.CreatedBy, CreatedAt = entity.CreatedAt, ModifiedAt = entity.ModifiedAt, ModifiedBy = entity.ModifiedBy, CountryId = entity.CountryId }; return(_repository.Add(city)); }
public ActionResult Add(CityDTO entity) { try { City c = new City(); c.Name = entity.Name; c.CountryID = entity.CountryID; cityRepository.Add(c); cityRepository.Save(); return(Json(entity, JsonRequestBehavior.DenyGet)); } catch (Exception e) { return(Json(false, JsonRequestBehavior.DenyGet)); } }
public async Task <IActionResult> AddCityAsync([FromBody] EditCityViewModel viewModel) { var city = viewModel.Adapt <City>(); var conflictingCities = await _cityRepository.GetAllAsync(x => x.Ibge == city.Ibge || (x.Name == city.Name && x.UF == city.UF)); if (conflictingCities.Any()) { return(Conflict($"Conflicting cities found")); } _cityRepository.Add(city); await _unitOfWork.CompleteAsync(); var result = city.Adapt <CityViewModel>(); return(Ok(result)); }
public async Task <Notifiable> Handle(CreateCityCommand request, CancellationToken cancellationToken) { var exists = await _repository.ExistsByName(request.Name, request.State); if (exists) { return(new Notifiable(new NotifiableError($"A cidade '{request.Name}' já está cadastrada"))); } var city = new City(request.Name, request.State); await _repository.Add(city); await _repository.Save(); return(new Notifiable("Cidade cadastrada com sucesso", city)); }
public async Task <IActionResult> Create([FromBody] City item) { if (item.CityId == 0) { await _repository.Add(item); return(CreatedAtRoute("GetCity", new { Controller = "City", id = item.CityId }, item)); } else { if (item.CityId > 0) { await _repository.Update(item); } } return(BadRequest()); }
public async Task <ActionResult <CityDto> > PostCity(CityDto cityDto) { try { var mappedEntity = _mapper.Map <City>(cityDto); _cityRepository.Add(mappedEntity); if (await _cityRepository.Save()) { return(Created($"/api/v1.0/cities/{mappedEntity.CityId}", _mapper.Map <CityDto>(mappedEntity))); } } catch (Exception exception) { return(StatusCode(StatusCodes.Status500InternalServerError, $"Database Failure: {exception.Message}")); } return(BadRequest()); }
public CityStatusViewModel CityCreate(CityCreateViewModel createCity) { var searchCity = _cityRepository.GetCityInCountry(createCity.CountryId, createCity.Name); if (searchCity != null) { return(CityStatusViewModel.CountryDublicate); } var city = new City { Name = createCity.Name, Priority = createCity.Priority, DateCreate = DateTime.Now, CountryId = createCity.CountryId }; _cityRepository.Add(city); _cityRepository.SaveChange(); return(CityStatusViewModel.Success); }
public IActionResult Add([FromBody] City city) { if (ModelState.IsValid) { var cityExists = _CityRepository.GetCityByNameAndCode(city.Name, city.Code); if (cityExists != null) { return(new ConflictResult()); } else { var result = _CityRepository.Add(city); return(Ok(result)); } } else { return(BadRequest()); } }
public IActionResult AddCity(CityRequest cityRequest) { var oblastId = cityRequest.OblastId; var cityName = cityRequest.Name; var oblast = _oblastRepository.GetOblast(oblastId); if (oblast == null) { return(NotFound("Oblast Not Found")); } var city = new City { Name = cityName, OblastId = oblastId, Oblast = oblast }; oblast.Cities.Add(city); _cityRepository.Add(city); _oblastRepository.Update(oblast); return(Ok("Successful")); }
/// <summary> /// The Save /// </summary> /// <param name="entity">The entity<see cref="City"/></param> /// <returns>The <see cref="ServiceResult"/></returns> public ServiceResult Save(City entity) { try { if (entity.Identifier == 0) { _repository.Add(entity); } else { _repository.Update(entity); } return(new ServiceResult(true)); } catch (Exception ex) { return(new ServiceResult(false) { Error = ex.ToString() }); } }
public async Task <ActionResult> Post(City city) { try { var existing = await repository.GetCityAsync(city.CityId); if (existing != null) { return(BadRequest("City name already in use!")); } var newPath = linkGenerator.GetPathByAction("Get", "Cities", new { name = city.Name }); if (string.IsNullOrWhiteSpace(newPath)) { return(BadRequest("Could not use city name!")); } repository.Add(city); if (await repository.SaveChangesAsync()) { var newCity = await repository.GetCityAsync(city.CityId); return(Created(newPath, newCity)); } return(Ok()); } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } }