public async Task <IActionResult> Create(CreateLocationViewModel model) { if (ModelState.IsValid) { Location newLocation = new Location() { LocationId = Guid.NewGuid().ToString(), LocationName = model.LocationName }; if (await _locationServices.CreateLocation(newLocation)) { var userMessage = new MessageVM() { CssClassName = "alert alert-success", Title = "Thành công", Message = "Tạo địa điểm mới thành công" }; TempData["UserMessage"] = JsonConvert.SerializeObject(userMessage); } else { var userMessage = new MessageVM() { CssClassName = "alert alert-danger", Title = "Không thành công", Message = "Đã có lỗi khi thao tác, xin mời thử lại" }; TempData["UserMessage"] = JsonConvert.SerializeObject(userMessage); }; } return(RedirectToAction(actionName: "Index", controllerName: "Location")); }
public ActionResult CreateLocation([FromBody] Location _location) { try{ return(Created("New location created!", _locationService.CreateLocation(_location))); }catch (Exception e) { return(BadRequest(e.ToString())); } }
public ActionResult Create([Bind(Include = "LocationCode,LocationName,LocationType")] Location location) { if (ModelState.IsValid) { service.CreateLocation(location); return(RedirectToAction("Index")); } return(View(location)); }