public async Task <IActionResult> Edit(int id, [Bind("Id,Email")] Subscribe subscribe) { if (id != subscribe.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(subscribe); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SubscribeExists(subscribe.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(subscribe)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,AppTitle,LogoPath,FooterLogoPath,Description,Address,Phone,Phone2,WorkOurs,Email,FacebookLink,InstagramLink,TwitterLink,HomePhoto1,HomePhoto2,HomePhoto3,AnnounceAdvantages,AgentAdvantages,CategoryPhoto1,CategoryPhoto2,CategoryPhoto3,CategoryPhoto4")] AppInfo appInfo) { if (id != appInfo.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(appInfo); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AppInfoExists(appInfo.Id)) { return(NotFound()); } else { throw; } } return(View()); } return(View(appInfo)); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] City city) { if (id != city.Id) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(city); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CityExists(city.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(city)); }
public async Task <IActionResult> Edit(int id, Agent agent, IFormFile image) { if (id != agent.Id) { return(NotFound()); } if (ModelState.IsValid) { try { string path = _context.Agents.AsNoTracking().FirstOrDefault(p => p.Id == id)?.ImagePath; if (image != null) { var ext = Path.GetExtension(image.FileName); string purePath = $"agent-{Guid.NewGuid()}{ext}"; string fileName = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Uploads", purePath); using (var fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write)) { image.CopyTo(fs); } agent.ImagePath = purePath; } else if (agent.ImagePathTemp != null) { agent.ImagePath = agent.ImagePathTemp; } _context.Update(agent); await _context.SaveChangesAsync(); if (!string.IsNullOrWhiteSpace(path) && string.IsNullOrWhiteSpace(agent.ImagePathTemp)) { System.IO.File.Delete(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", path)); } } catch (DbUpdateConcurrencyException) { if (!AgentExists(agent.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(agent)); }
public async Task <IActionResult> CommentAdd(int homeId, string message) { if (ModelState.IsValid) { var userId = User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier)?.Value; if (userId == null) { return(Json(new { error = true, message = "Daxil Olun" })); } var owner = db.Users.FirstOrDefault(a => a.Id == int.Parse(userId)); var home = db.Homes.FirstOrDefault(h => h.Id == homeId); home.Comments = new List <Comment>(); var comment = new Comment { Message = message, OwnerId = int.Parse(userId), HomeId = homeId }; home.Comments.Add(comment); db.Update(home); await db.SaveChangesAsync(); var date = comment.CreatedDate.ToString("dddd, dd MMMM yyyy"); return(Json(new { error = false, message = "Yorum elava olundu", ownerName = owner.UserName, date = date, commentMesage = message })); } return(Json(new { error = true, message = "Xəta baş verdi" })); }
public async Task <IActionResult> Edit(int id, Home home, string[] oldFiles) { if (id != home.Id) { return(NotFound()); } #region edits if (home.Period == "All") { home.Period = null; } if (home.AgentId == 0) { home.AgentId = null; } if (home.CityId == 0) { home.CityId = null; } if (home.MetroId == 0) { home.MetroId = null; } if (home.AnnounceType == "Sale") { home.Period = null; } if (home.BakuDistrictId == 0) { home.BakuDistrictId = null; } if (home.NMRDistrictId == 0) { home.NMRDistrictId = null; } if (home.CityId != 6 && home.CityId != 1) { home.BakuDistrictId = null; home.NMRDistrictId = null; } if (home.CityId != 1) { home.MetroId = null; } if (home.CategoryId != 6) { home.Floor = null; } #endregion if (ModelState.IsValid) { try { if (oldFiles != null) { //var oldHome = _context.Homes.Include(h => h.Images).FirstOrDefault(h => h.Id == id); foreach (var item in _context.HomeImages.Where(h => h.HomeId == home.Id)) { if (!oldFiles.Contains(item.Path)) { System.IO.File.Delete(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", item.Path)); _context.HomeImages.Remove(item); //home.Images.Remove(item); } } } if (home.file != null) { home.Images = new List <HomeImage>(); for (int i = 0; i < home.file.Length; i++) { string ext = Path.GetExtension(home.file[i].FileName); string purePath = $"home-{Guid.NewGuid()}{ext}"; string fileName = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "uploads", purePath); using (var fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write)) { home.file[i].CopyTo(fs); } home.Images.Add(new HomeImage { Path = purePath }); } } _context.Update(home); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HomeExists(home.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["AgentId"] = new SelectList(_context.Agents, "Id", "Name", home.AgentId); ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Name", home.CategoryId); ViewData["CityId"] = new SelectList(_context.Cities, "Id", "Name", home.CityId); ViewData["MetroId"] = new SelectList(_context.Metros, "Id", "Name", home.MetroId); ViewData["BakuDistrictId"] = new SelectList(_context.BakuDistricts, "Id", "Name", home.BakuDistrictId); ViewData["NMRDistrictId"] = new SelectList(_context.NMRDistricts, "Id", "Name", home.NMRDistrictId); return(View(home)); }