public IActionResult Edit([FromForm] CountryEditModel entity) { if (ModelState.IsValid) { string currentUser = HttpContext?.User?.Identity?.Name; if (!String.IsNullOrEmpty(currentUser)) { AuditedEntityMapper <CountryEditModel> .FillModifyAuditedEntityFields(entity, currentUser); try { _countryService.Update(entity); } catch (DbUpdateConcurrencyException) { if (!CountryExists(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 IActionResult Edit([FromBody] CategoryEditModel entity) { if (ModelState.IsValid) { string currentUser = HttpContext?.User?.Identity?.Name; if (!String.IsNullOrEmpty(currentUser)) { AuditedEntityMapper <CategoryEditModel> .FillModifyAuditedEntityFields(entity, currentUser); try { _categoryService.Update(entity); } catch (DbUpdateConcurrencyException) { if (!CategoryExists(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(Ok().WithSuccess(LOCALIZATION_SUCCESS_DEFAULT)); } else { _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN); return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN)); } } return(View(entity)); }
public IActionResult Edit([FromForm] AdEditModel entity) { if (ModelState.IsValid) { string currentUser = HttpContext?.User?.Identity?.Name; if (!String.IsNullOrEmpty(currentUser)) { AuditedEntityMapper <AdEditModel> .FillModifyAuditedEntityFields(entity, currentUser); entity.OwnerId = CurrentUserId; #region File Map //need to map files in controller because aspnet core assembly is present in adsite project string[] result; if (!String.IsNullOrEmpty(entity.SerializedAdDetailsPictures)) { result = Newtonsoft.Json.JsonConvert.DeserializeObject <string[]>(entity.SerializedAdDetailsPictures); entity.MainPictureFile = StripComments(entity.MainPictureFile); entity.MainPictureFile = Newtonsoft.Json.JsonConvert.DeserializeObject <string>(entity.MainPictureFile); EntityFormMap(result, entity); } else { MapFiles(entity); } // #endregion try { _adService.Update(entity); } catch (DbUpdateConcurrencyException) { if (!AdExists(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(MyAds)).WithSuccess(LOCALIZATION_SUCCESS_DEFAULT)); } else { _logger.LogError(LOCALIZATION_ERROR_USER_MUST_LOGIN); return(NotFound().WithError(LOCALIZATION_ERROR_USER_MUST_LOGIN)); } } ViewBag.Cities = _cityService.GetAllAsLookup(CountryId); ViewBag.Categories = _categoryService.GetAllAsLookup(CountryId); #region Preserve pictures if model validation fails string serializedString = String.Empty; string mainPictureSerializedString = string.Empty; if (entity.Files != null && entity.Files.Count() > 0) { MapFiles(entity); serializedString = Newtonsoft.Json.JsonConvert.SerializeObject(entity.FilesAsListOfByteArray); mainPictureSerializedString = Newtonsoft.Json.JsonConvert.SerializeObject(entity.FilesAsListOfByteArray.First()); } if (!String.IsNullOrEmpty(entity.SerializedAdDetailsPictures)) { string[] convertResult = Newtonsoft.Json.JsonConvert.DeserializeObject <string[]>(entity.SerializedAdDetailsPictures); EntityFormMap(convertResult, entity); serializedString = Newtonsoft.Json.JsonConvert.SerializeObject(entity.FilesAsListOfByteArray); mainPictureSerializedString = Newtonsoft.Json.JsonConvert.SerializeObject(entity.FilesAsListOfByteArray.First()); } ViewBag.SerializedPictures = serializedString; ViewBag.MainPictureSerializedString = mainPictureSerializedString; #endregion return(View(entity).WithWarning(LOCALIZATION_WARNING_INVALID_MODELSTATE)); }
public void Put([FromBody] CityEditModel model) { AuditedEntityMapper <CityEditModel> .FillModifyAuditedEntityFields(model, HttpContext?.User?.Identity?.Name); Ok(_cityService.Update(model)); }