public ActionResult TenantEdit(Tenant model,int ApartmentID, int BuildingID) { //this i use forthe link since model didn't pass Nav properties db.Tenant.Attach(model); var Entry = db.Entry(model); Entry.Property(c => c.FirstName).IsModified = true; Entry.Property(c => c.LastName).IsModified = true; Entry.Property(c => c.Phone).IsModified = true; Entry.Property(c => c.Username).IsModified = true; db.SaveChanges(); return RedirectToAction("ApartmentProfile", new { ApartmentID = ApartmentID, BuildingID =BuildingID}); }
public async Task<ActionResult> AddingTenant(TenantVM newTenant) { try { if (ModelState.IsValid) { var newtenant = new Tenant { FirstName = newTenant.FirstName, LastName = newTenant.LastName, Phone = newTenant.Phone, Created = DateTime.Now, aptID = newTenant.aptID, Username = newTenant.Username }; db.Tenant.Add(newtenant); await db.SaveChangesAsync(); return RedirectToAction("ApartmentProfile", new { ApartmentID = newTenant.aptID, BuildingID= newTenant.BuildingID }); } } catch(Exception e){ ViewBag.Message = e.Message; } return View(); }