public ActionResult DefineRoute(AccountDetailModel model) { if (ModelState.IsValid) { var user = context.Users .Include(x => x.Profile) .FirstOrDefault(x => x.Username == User.Identity.Name); if (user != null) { var profile = new Profile { FirstStartAddress = model.FirstStartAddress, FirstEndAddress = model.FirstEndAddress, FirstStartDistance = null, FirstEndDistance = null, FirstRouteName = model.FirstRouteName, FirstRoute = model.FirstRoute, FirstMarkets = model.FirstMarkets, SecondStartAddress = model.SecondStartAddress, SecondEndAddress = model.SecondEndAddress, SecondStartDistance = null, SecondEndDistance = null, SecondRouteName = model.SecondRouteName, SecondRoute = model.SecondRoute, SecondMarkets = model.SecondMarkets, ThirdStartAddress = model.ThirdStartAddress, ThirdEndAddress = model.ThirdEndAddress, ThirdStartDistance = null, ThirdEndDistance = null, ThirdRouteName = model.ThirdRouteName, ThirdRoute = model.ThirdRoute, ThirdMarkets = model.ThirdMarkets }; user.Profile = profile; context.SaveChanges(); TempData["DefineRoute"] = "Success"; return RedirectToAction("AccountDetails", "Account"); } ModelState.AddModelError("", "Username không tồn tại!"); } // Something's wrong, redisplay the form TempData["DefineRoute"] = "Fail"; return RedirectToAction("AccountDetails", "Account"); }
public Profile getProfile(string username) { //var result = new Profile(); var profile = context.Profiles.Where(p => p.Username.Equals(username)).FirstOrDefault(); var result = new Profile { Username = username, FirstRoute = profile.FirstRoute, FirstStartAddress = profile.FirstStartAddress, FirstEndAddress = profile.FirstEndAddress, FirstRouteName = profile.FirstRouteName, SecondRoute = profile.SecondRoute, SecondRouteName = profile.SecondRouteName, SecondStartAddress = profile.SecondStartAddress, SecondEndAddress = profile.SecondEndAddress, ThirdRoute = profile.ThirdRoute, ThirdRouteName = profile.ThirdRouteName, ThirdStartAddress = profile.ThirdStartAddress, ThirdEndAddress = profile.ThirdEndAddress, }; return result; }