public ActionResult UpdateRoute(RouteUpdateModel model) { var route = new Route(); route.Id = model.Id; route.RouteType = model.RouteType; if (model.RouteType == 1) { var item = routeSrv.GetRoute(route.Id); route.Name = item.Name; route.Lines = item.Lines; route.GroupId = item.GroupId; route.Memo = item.Memo; route.Geo = model.Geo; route.CreateTime = item.CreateTime; route.UpdateTime = DateTime.UtcNow; routeSrv.UpdateRoute(route); } else { //修改地铁 } return(Json(new { success = true, data = routeSrv.GetRoute(route.Id) })); }
public async Task <IActionResult> Update([FromQuery] int id, [FromBody] RouteUpdateModel model) { if (!ModelState.IsValid) { return(WrapResponse(new Result <RouteUpdateModel>(WrapModelStateErrors(ModelState)))); } var result = await _routeService.Update(id, model); return(WrapResponse(result, HttpStatusCode.NoContent)); }
public async Task <Result <object> > Update(int id, RouteUpdateModel item) { try { var entity = _routeRepository.GetSingle(id); if (entity != null) { if (await CheckUsersPermission(entity)) { if (await _userResolver.IsConfirmed()) { entity.Difficulty = item.Difficulty; entity.Name = item.Name; _routeRepository.Update(entity); await _routeRepository.Commit(); return(new Result <object>()); } else { ErrorResult error = GenerateError("User is not confirmed", "", "", ErrorStatus.Forbidden); return(new Result <object>(error)); } } else { ErrorResult error = GenerateError("Action forbidden", "", "", ErrorStatus.Forbidden); return(new Result <object>(error)); } } else { ErrorResult error = GenerateError("Route not found", "Id", "Invalid identifier", ErrorStatus.ObjectNotFound); return(new Result <object>(error)); } } catch (Exception ex) { ErrorResult error = GenerateError(ex); return(new Result <object>(error)); } }
public bool AddOrUpdateRoute(RouteUpdateModel routeModel) { Route route; if (routeModel.RouteId != default(int)) { route = Db.Route.First(x => x.IsActive); } else { route = new Route() { IsActive = true, }; Db.Route.Add(route); } route.DepartureLocationId = routeModel.DepartureLocationId; route.DestinationLocationId = routeModel.DestinationLocationId; Db.SaveChanges(); return(true); }
public bool AddOrUpdateRoute([FromBody] RouteUpdateModel route) { return(_service.AddOrUpdateRoute(route)); }