public async Task EditAsync(CityEditModel cityEdit) { var original = this.citiesRepository .All() .First(x => x.Id == cityEdit.CityId); original.Name = cityEdit.Name; await this.citiesRepository.SaveChangesAsync(); }
public static CityEditModel MapToCityEditModel(City entity) { var editModel = new CityEditModel(); editModel.ID = entity.ID; editModel.Name = entity.Name; editModel.Postcode = entity.Postcode; return(editModel); }
public virtual ActionResult Create(CityEditModel model) { if (!ModelState.IsValid) { return(View(model)); } var id = _cities.Add(model); return(RedirectToAction(MVC.City.Edit(id))); }
public virtual ActionResult Edit(long id, CityEditModel model) { if (!ModelState.IsValid) { return(View(model)); } _cities.Edit(id, model); return(RedirectToAction(MVC.City.Edit(id))); }
public async Task <bool> Edit(CityEditModel model) { var country = await _repository.Filter <City>(x => x.Id == model.Id).FirstOrDefaultAsync(); if (country == null) { throw new Exception("Country not found"); } country.Name = model.Name; _repository.Update(country); await _repository.SaveChangesAsync(); return(true); }
public bool Update(CityEditModel entity) { City city = _repository.Get(entity.ID); if (city == null) { throw new Exception(LOCALIZATION_GENERAL_NOT_FOUND + entity.ID); } city.Name = entity.Name; city.Postcode = entity.Postcode; city.ModifiedAt = entity.ModifiedAt; city.ModifiedBy = entity.ModifiedBy; return(_repository.Update(city)); }
public IActionResult Edit([FromForm] CityEditModel entity) { if (ModelState.IsValid) { string currentUser = HttpContext?.User?.Identity?.Name; if (!String.IsNullOrEmpty(currentUser)) { AuditedEntityMapper <CityEditModel> .FillModifyAuditedEntityFields(entity, currentUser); try { _cityService.Update(entity); } catch (DbUpdateConcurrencyException) { if (!CityExists(entity.ID)) { _logger.LogError(LOCALIZATION_ERROR_NOT_FOUND); return(NotFound().WithError(LOCALIZATION_ERROR_NOT_FOUND)); } else { _logger.LogError(LOCALIZATION_ERROR_CONCURENT_EDIT); return(NotFound().WithError(LOCALIZATION_ERROR_CONCURENT_EDIT)); } } return(RedirectToAction(nameof(Details), new { id = entity.ID }).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT)); } else { _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN); return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN)); } } return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE)); }
public async Task <IActionResult> Put(CityEditModel cityEdit) { var response = new Response(); var exists = this.citiesService.Exists(x => x.Id == cityEdit.CityId); var existsByName = this.citiesService.Exists(x => x.Id != cityEdit.CityId && x.Name == cityEdit.Name); if (!this.ModelState.IsValid || existsByName) { response.Message = "City with that name already exists!"; return(this.BadRequest(response)); } if (!exists) { response.Message = "No such city!"; return(this.NotFound(response)); } await this.citiesService.EditAsync(cityEdit); response.Message = "Successfully edited city!"; return(this.Ok(response)); }
public void Edit(long id, CityEditModel model) { _cities.Update(id, model.EnglishName, model.RussianName, model.Position); }
public long Add(CityEditModel model) { return(_cities.Add(model.EnglishName, model.RussianName, model.Position)); }
public async Task <IActionResult> Edit([FromBody] CityEditModel model) { return(await MakeActionCallAsync(async() => await _cityService.Edit(model))); }
public void Put([FromBody] CityEditModel model) { AuditedEntityMapper <CityEditModel> .FillModifyAuditedEntityFields(model, HttpContext?.User?.Identity?.Name); Ok(_cityService.Update(model)); }
public EditViewModel(CityEditModel model) : base(model) { }