public void InsertTown(TownDto townObject) { InvokeService <IDemoServerServiceContract>(c => { c.InsertTown(townObject); }); }
public async Task <TownDto> CreateTown(TownDto townDto) { var townToCreate = _mapper.Map <Town>(townDto); var newTown = await CreateAndReturn(townToCreate); return(_mapper.Map <TownDto>(newTown)); }
public async Task <TownDto> UpdateTown(TownDto townDto) { var townToUpdate = _mapper.Map <Town>(townDto); var updatedTown = await UpdateAndReturn(townToUpdate); return(_mapper.Map <TownDto>(updatedTown)); }
// ModifyUser <username> <property> <new value> public string Execute(string[] data) { string username = data[0]; ModifyUserDto userDTO = userService.ByUsername <ModifyUserDto>(username); if (userDTO == null || userDTO.IsDeleted == true) { throw new ObjectNotFoundException(typeof(User).Name, username); } var modifiableProperties = userDTO.GetType() .GetProperties().Select(pi => pi.Name); string propertyName = data[1]; if (!modifiableProperties.Contains(propertyName)) { throw new PropertyNotSupportedException(propertyName); } string propertyValue = data[2]; switch (propertyName.ToUpper()) { case "BORNTOWN": TownDto townDTO = townService.ByName <TownDto>(propertyValue); if (townDTO == null) { throw new InvalidValueException( propertyValue, Environment.NewLine + new ObjectNotFoundException(typeof(Town).Name, propertyValue).Message); } userService.SetBornTown(userDTO.Id, townDTO.Id); break; case "CURRENTTOWN": townDTO = townService.ByName <TownDto>(propertyValue); if (townDTO == null) { throw new InvalidValueException( propertyValue, Environment.NewLine + new ObjectNotFoundException(typeof(Town).Name, propertyValue).Message); } userService.SetCurrentTown(userDTO.Id, townDTO.Id); break; case "PASSWORD": if (!IsPasswordValid(propertyValue)) { throw new InvalidValueException( propertyValue, Environment.NewLine + new InvalidObjectException("password").Message); } userService.ChangePassword(userDTO.Id, propertyValue); break; default: throw new PropertyNotSupportedException(propertyName); } return(String.Format(SuccessMessage, username, propertyName, propertyValue)); }
public async Task <IActionResult> CreateTown() { var countriesList = await _serviceTown.GetCountries(); ViewBag.TotalCountries = countriesList; TownDto townDto = new TownDto(); return(PartialView("_TownModelPartial", townDto)); }
public async Task <TownDto> EditTown(TownDto townDto) { var town = _mapper.Map <Town>(townDto); _context.Towns.Update(town); await _context.SaveChangesAsync(); return(townDto); }
public bool UpdateTown(TownDto townObject) { bool res = false; InvokeService <IDemoServerServiceContract>(c => { c.UpdateTown(townObject); }); return(res); }
public void ImportTown(TownDto townDto) { string townName = townDto.Name; InputDataValidator.ValidateStringMaxLength(townName, Constants.MaxTownNameLength); townValidator.ValidateTownDoesNotExist(townName); townService.AddTown(townName); Console.WriteLine(string.Format(Constants.ImportSuccessMessages.TownAddedSuccess, townName)); }
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))); }
public async Task <IActionResult> Delete(int id) { TownDto townDto = await _townService.GetTown(id); if (townDto == null) { return(NotFound("No such town")); } await _townService.DeleteTown(id); return(Ok()); }
public async Task <IActionResult> Post([FromBody] TownCreateModel townCreateModel) { if (await _townService.Exists(townCreateModel.Title)) { return(Conflict($"Such town already exists")); } TownDto townCreateDto = _mapper.Map <TownDto>(townCreateModel); TownDto createdTownDto = await _townService.CreateTown(townCreateDto); TownWebModel createdTownModel = _mapper.Map <TownWebModel>(createdTownDto); return(CreatedAtAction(nameof(Get), new { id = createdTownModel.TownId }, createdTownModel)); }
public async Task <TownDto> CreateTown(TownDto townDto) { var town = new Town { TownName = townDto.TownName, PostalCode = townDto.PostalCode, CountryId = townDto.CountryId }; _context.Add(town); await _context.SaveChangesAsync(); return(townDto); }
internal static TownDto GetEntity(Town town) { if (town == null) { throw new ArgumentNullException("Town", "Mapping TownDto TO Town"); } var townDto = new TownDto(); townDto.TownId = town.TownId; townDto.TownName = town.TownName; townDto.City = town.City; return(townDto); }
public void InsertTown(TownDto townObject) { try { da.Insert <Town>(new Town() { TownId = townObject.TownId, TownName = townObject.TownName, City = townObject.City }); } catch (Exception) { throw; } }
public async Task <IActionResult> Put([FromBody] TownUpdateModel townUpdateModel) { TownDto townDto = await _townService.GetTown(townUpdateModel.TownId); if (townDto == null) { return(NotFound($"No such town with id: {townUpdateModel.TownId}")); } if (townDto.Title != townUpdateModel.Title && await _townService.Exists(townUpdateModel.Title)) { return(Conflict($"Such town already exists with title {townUpdateModel.Title} ")); } TownDto townCreateDto = _mapper.Map <TownDto>(townUpdateModel); TownDto updatedTownDto = await _townService.UpdateTown(townCreateDto); TownWebModel updatedTownModel = _mapper.Map <TownWebModel>(updatedTownDto); return(CreatedAtAction(nameof(Get), new { id = updatedTownModel.TownId }, updatedTownModel)); }
public bool UpdateTown(TownDto townObject) { try { if (da.Update <Town>(new Town() { TownId = townObject.TownId, TownName = townObject.TownName, City = townObject.City }) == 1) { return(true); } } catch (Exception ex) { throw; } return(false); }
public async Task <IActionResult> CreateTown(TownDto townDto) { if (!ModelState.IsValid) { return(PartialView("_TownModelPartial", townDto)); } else { try { await _serviceTown.CreateTown(townDto); return(RedirectToAction("Index")); } catch (Exception ex) { return(PartialView("_TownModelPartial", townDto)); } } }
public async Task <IActionResult> EditTown(TownDto townDto) { if (!ModelState.IsValid) { //ModelState.AddModelError("", ""); return(View(townDto)); } else { try { await _serviceTown.EditTown(townDto); return(RedirectToAction("Index")); } catch (Exception ex) { return(BadRequest(ex)); } } }
// AddTown <townName> <countryName> public string Execute(string[] data) { if (!userSessionService.IsLoggedIn()) { throw new InvalidOperationException("Invalid credentials!"); } string townName = data[0]; string country = data[1]; var townExists = townService.Exists(townName); if (townExists) { throw new ArgumentException($"Town {townName} was already added!"); } var townDto = new TownDto() { TownName = townName, CountryName = country }; var town = townService.Add(townName, country); return($"Town {townName} was added successfully!"); }
public async Task <DinazorResult> Update(TownDto t) { return(await _townOperation.Update(t)); }
public async Task <TownDto> UpdateTown(TownDto townUpdateDto) { TownDto updatedTown = await _townRepository.UpdateTown(townUpdateDto); return(updatedTown); }
public async Task <TownDto> CreateTown(TownDto townDto) { var newTown = await _townRepository.CreateTown(townDto); return(newTown); }