public IActionResult EditSocialData(AppDataUpdateViewModel model) { if (ModelState.IsValid) { AppSocialAddress item = _appRepository.GetInfo(model.Id); item.UrlAddress = model.UrlAddress; if (model.AppSocialImgs != null) { if (model.ExistingSocialImagePath != null) { string filePath = Path.Combine(_hostingEnvironment.WebRootPath, "images", model.ExistingSocialImagePath); System.IO.File.Delete(filePath); } item.AppSocialImg = ProcessUploadAppSocialImage(model); } _appRepository.Update(item); TempData["message"] = $"Object {item.UrlAddress} was edited."; return(RedirectToAction("SocialList")); } return(View()); }
public AppSocialAddress Update(AppSocialAddress data) { var item = _repository.AppSocialAddresses.Attach(data); item.State = Microsoft.EntityFrameworkCore.EntityState.Modified; _repository.SaveChanges(); return(data); }
public async Task <IActionResult> DeleteSocialAddress(int id) { AppSocialAddress deletePerson = await _appRepository.Delete(id); if (deletePerson != null) { TempData["message"] = $"Url address: {deletePerson.UrlAddress} was deleted"; } return(RedirectToAction("SocialList")); }
public async Task <AppSocialAddress> Delete(int id) { AppSocialAddress item = await _repository.AppSocialAddresses.FindAsync(id); if (item != null) { _repository.AppSocialAddresses.Remove(item); _repository.SaveChanges(); } return(item); }
public IActionResult EditSocialData(int id) { AppSocialAddress data = _appRepository.GetInfo(id); AppDataUpdateViewModel item = new AppDataUpdateViewModel { Id = data.Id, UrlAddress = data.UrlAddress, ExistingSocialImagePath = data.AppSocialImg }; TempData["message"] = $"Object {item.UrlAddress} was selected."; return(View(item)); }
public IActionResult CreateSocialData(AppDataCreateViewModel model) { if (ModelState.IsValid) { string uniqueSocialFileName = ProcessUploadAppSocialImage(model); AppSocialAddress newAppSocialAddress = new AppSocialAddress { UrlAddress = model.UrlAddress, AppSocialImg = uniqueSocialFileName }; _appRepository.Add(newAppSocialAddress); TempData["message"] = $"Address {model.UrlAddress} was created."; return(RedirectToAction("SocialList")); } return(View()); }
public AppSocialAddress Add(AppSocialAddress data) { _repository.AppSocialAddresses.Add(data); _repository.SaveChanges(); return(data); }