public IActionResult Update(string id, string fromProfileUpdate) { int clientId = Convert.ToInt32(id); ClientUpdateVM model = _context.Clients.Include(x => x.Country) .Include(x => x.City) .Include(x => x.ClientType) .Where(x => x.IsDeleted == false && x.ClientId == clientId) .Select(x => new ClientUpdateVM { ClientId = x.ClientId, CountryId = x.CountryId, CityId = x.CityId, ClientTypeId = x.ClientTypeId, Address = x.Address, FirstName = x.FirstName, LastName = x.LastName, Email = x.Email, Phone = x.Phone, IsDeleted = x.IsDeleted, Countries = new SelectList(GetCountries(), "CountryId", "Name", x.CountryId), ClientTypes = new SelectList(GetClientTypes(), "ClientTypeId", "Name", x.ClientTypeId) }).FirstOrDefault(); if (Convert.ToInt32(fromProfileUpdate) == 1) { model.FromProfileUpdate = Convert.ToInt32(fromProfileUpdate); return(PartialView("_UpdateFromProfile", model)); } return(PartialView("_Update", model)); }
public IActionResult Update(ClientUpdateVM model) { model.Countries = new SelectList(GetCountries(), "CountryId", "Name"); model.ClientTypes = new SelectList(GetClientTypes(), "ClientTypeId", "Name"); if (!ModelState.IsValid) { Response.StatusCode = 400; if (model.FromProfileUpdate == 1) { return(PartialView("_UpdateFromProfile", model)); } return(PartialView("_Update", model)); } try { Client client = new Client(); client.CopyObject(model); _context.Clients.Update(client); _context.SaveChanges(); _ajaxFlashMessage.Success("Client updated"); if (model.FromProfileUpdate == 1) { //return RedirectToAction("Details", new { id = model.ClientId }); return(PartialView("_UpdateFromProfile", model)); } return(PartialView("_Update", model)); } catch (Exception ex) { _ajaxFlashMessage.Danger("Error while updating client"); return(PartialView("Error")); } }