Exemplo n.º 1
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var valueProvider = bindingContext.ValueProvider;
            var model = new GcuEditModel();

            try
            {
                model.GcuType = GetGcu(valueProvider);
                model.UavTypes = GetSupportedUavs(valueProvider);
                return model;
            }
            catch (Exception ex)
            {
                model.BindingError = ex;
                return model;
            }
        }
Exemplo n.º 2
0
        public ActionResult EditGcu(GcuEditModel model)
        {
            if (!ModelState.IsValid || model.BindingError != null)
            {
                TempData["error"] = "Ошибка связывателя:" + model.BindingError.Message;
                return RedirectToAction("index", "admin");
            }

            if (_db.SaveGcu(model))
                TempData["success"] = "Изменения в элементе были сохранены";
            else
                TempData["error"] = "Ошибка метода соханения";

            return RedirectToAction("show", "admin", new { type = "gcus", _id = model.GcuType.Id });
        }
Exemplo n.º 3
0
        public bool SaveGcu(GcuEditModel model)
        {
            if (model.GcuType == null || model.UavTypes == null)
                return false;

            var temp = _db.Gcus.Get(model.GcuType.Id);

            switch (temp.Id)
            {
                case 1:
                    {
                        #region Portable
                        var gcu = temp as Portable;
                        var gcuDto = model.GcuType as PortableDTO;
                        gcu.DeployTime = gcuDto.DeployTime;
                        gcu.Name = gcuDto.Name;
                        gcu.Size = gcuDto.Size;
                        gcu.Places = gcuDto.Places;
                        gcu.SupportedUavs.Clear();

                        foreach (var item in model.UavTypes)
                            gcu.SupportedUavs.Add(_db.Uavs.GetAll.First(x => x.Id == item.Id));

                    }
                    break;
                #endregion
                case 2:
                    {
                        #region Mobile
                        var gcu = temp as Mobile;
                        var gcuDto = model.GcuType as MobileDTO;

                        gcu.CarType = gcuDto.CarType;
                        gcu.Name = gcuDto.Name;
                        gcu.Size = gcuDto.Size;
                        gcu.Places = gcuDto.Places;

                        gcu.SupportedUavs.Clear();

                        foreach (var item in model.UavTypes)
                            gcu.SupportedUavs.Add(_db.Uavs.GetAll.First(x => x.Id == item.Id));
                    }
                    break;
                    #endregion
                case 3:
                    {
                        #region Stationary
                        var gcu = temp as Stationary;
                        var gcuDto = model.GcuType as StationaryDTO;

                        gcu.DeployPlaces = gcuDto.DeployPlaces;
                        gcu.Name = gcuDto.Name;
                        gcu.Size = gcuDto.Size;
                        gcu.Places = gcuDto.Places;

                        gcu.SupportedUavs.Clear();

                        foreach (var item in model.UavTypes)
                            gcu.SupportedUavs.Add(_db.Uavs.GetAll.First(x => x.Id == item.Id));
                    }
                    break;
#endregion
                default:
                    return false;
            }
            return _db.Save();
        }