public ActionResult Create(UserLocationCreateDTO ulcDto) { ulcDto.UserId = User.Identity.GetUserId(); if (ModelState.IsValid) { _repo.CreateUserLocation(ulcDto); return RedirectToAction("Index"); } var errors = ModelState.Values.SelectMany(v => v.Errors); return View(ulcDto); }
// A method to create the User Location public void CreateUserLocation(UserLocationCreateDTO ulcDto) { // ulcDto to userLocation model mapping UserLocation userLocation = new UserLocation(); userLocation.UserLocationName = ulcDto.UserLocationName; userLocation.Latitude = ulcDto.Latitude; userLocation.Longitude = ulcDto.Longitude; userLocation.LastEmailTime = DateTime.Now.AddHours(-1.0); userLocation.Radius = ulcDto.Radius; userLocation.UserId = ulcDto.UserId; _db.UserLocations.Add(userLocation); _db.SaveChanges(); }