public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var valueProvider = bindingContext.ValueProvider; var model = new PayloadEditModel(); try { model.Payload = GetPayload(valueProvider); model.UavTypes = GetSupportedUavs(valueProvider); return model; } catch (Exception ex) { model.BindingError = ex; return model; } }
public ActionResult EditPayload(PayloadEditModel model) { if (!ModelState.IsValid || model.BindingError != null) { TempData["error"] = "Ошибка связывателя:" + model.BindingError.Message; return RedirectToAction("index", "admin"); } if (_db.SavePayload(model)) TempData["success"] = "Изменения в элементе были сохранены"; else TempData["error"] = "Ошибка метода соханения"; return RedirectToAction("show", "admin", new { type = "plds", _id = model.Payload.Id }); }
public bool SavePayload(PayloadEditModel model) { if (model.Payload == null || model.UavTypes == null) return false; var temp = (model.Payload.Id != 0) ? _db.Payloads.Get(model.Payload.Id) : new Payload(); switch (model.Payload.Id) { case 1: { #region Photo var cam = temp as Photo; var camDto = model.Payload as PhotoDTO; cam.ImageFormat = camDto.ImageFormat; cam.Lens = camDto.Lens; cam.PictureElements = camDto.PictureElements; cam.PitchRotation = camDto.PitchRotation; cam.RollingRig = camDto.RollingRig; cam.Stabilization = camDto.Stabilization; cam.WatchingCamera = camDto.WatchingCamera; cam.Weight = camDto.Weight; cam.SupportedUavs.Clear(); foreach (var item in model.UavTypes) cam.SupportedUavs.Add(_db.Uavs.GetAll.First(x => x.Id == item.Id)); } break; #endregion case 2: { #region TV var cam = temp as TV; var camDto = model.Payload as TVDTO; cam.EffectivePictureElements = camDto.EffectivePictureElements; cam.Gimbal = camDto.Gimbal; cam.LinearResolution = camDto.LinearResolution; cam.PitchRotation = camDto.PitchRotation; cam.RollingRig = camDto.RollingRig; cam.Stabilization = camDto.Stabilization; cam.Zoom = camDto.Zoom; cam.Weight = camDto.Weight; cam.SupportedUavs.Clear(); foreach (var item in model.UavTypes) cam.SupportedUavs.Add(_db.Uavs.GetAll.First(x => x.Id == item.Id)); } break; #endregion case 3: { #region IR var cam = temp as IR; var camDto = model.Payload as IRDTO; cam.DispalyFormat = cam.DispalyFormat; cam.Lens = camDto.Lens; cam.Gimbal = camDto.Gimbal; cam.FullFrameRates = camDto.FullFrameRates; cam.PitchRotation = camDto.PitchRotation; cam.RollingRig = camDto.RollingRig; cam.Stabilization = camDto.Stabilization; cam.WatchingCamera = camDto.WatchingCamera; cam.Weight = camDto.Weight; cam.HorizontalResolution = camDto.HorizontalResolution; cam.LinearResolution = camDto.LinearResolution; cam.SpectralBand = camDto.SpectralBand; cam.SupportedUavs.Clear(); foreach (var item in model.UavTypes) cam.SupportedUavs.Add(_db.Uavs.GetAll.First(x => x.Id == item.Id)); } break; #endregion case 4: { #region Frontal var cam = temp as Frontal; var camDto = model.Payload as FrontalDTO; cam.AngleOfView = camDto.AngleOfView; cam.Lens = camDto.Lens; cam.Definition = camDto.Definition; cam.SpectralBand = camDto.SpectralBand; cam.Weight = camDto.Weight; cam.SupportedUavs.Clear(); foreach (var item in model.UavTypes) cam.SupportedUavs.Add(_db.Uavs.GetAll.First(x => x.Id == item.Id)); } break; #endregion case 5: { #region MS var cam = temp as Multispectral; var camDto = model.Payload as MultispectralDTO; cam.CameraCoverage = camDto.CameraCoverage; cam.Dimensions = camDto.Dimensions; cam.ImageResolution = camDto.ImageResolution; cam.MeasurementRange = camDto.MeasurementRange; cam.RateOfFrameRecording = camDto.RateOfFrameRecording; cam.ResolutionOfCourseCamera = camDto.ResolutionOfCourseCamera; cam.Weight = camDto.Weight; cam.SupportedUavs.Clear(); foreach (var item in model.UavTypes) cam.SupportedUavs.Add(_db.Uavs.GetAll.First(x => x.Id == item.Id)); } break; #endregion case 10: { #region Otus var cam = temp as Otus; var camDto= model.Payload as OtusDTO; cam.Feedback = camDto.Feedback; cam.GimbalSystem = camDto.GimbalSystem; cam.PanTilRange = camDto.PanTilRange; cam.Interfaces = camDto.Interfaces; cam.RangeFinder = camDto.RangeFinder; cam.Stabiliz = camDto.Stabiliz; cam.Temperature = camDto.Temperature; cam.Weight = camDto.Weight; cam.SupportedUavs.Clear(); foreach (var item in model.UavTypes) cam.SupportedUavs.Add(_db.Uavs.GetAll.First(x => x.Id == item.Id)); } break; #endregion default: return false; } return _db.Save(); }