예제 #1
0
        public ActionResult Save(Storage storage)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new StorageFormViewModel()
                {
                    Storage   = storage,
                    Locations = unitOfWork.Locations.GetLocations()
                };

                return(View("StorageForm", viewModel));
            }

            if (storage.Id == 0)// create
            {
                unitOfWork.Storages.AddStorage(storage);
            }
            else // edit
            {
                var storageDb = unitOfWork.Storages.GetStorage(storage.Id);
                storageDb.Name       = storage.Name;
                storageDb.LocationId = storage.LocationId;
                storageDb.Street     = storage.Street;
            }

            unitOfWork.Complete();

            return(RedirectToAction("Index", "Storages"));
        }
예제 #2
0
        public ActionResult New()
        {
            var viewModel = new StorageFormViewModel()
            {
                Storage   = new Storage(),
                Locations = unitOfWork.Locations.GetLocations()
            };

            return(View("StorageForm", viewModel));
        }
예제 #3
0
        public ActionResult Edit(int id)
        {
            var storage = unitOfWork.Storages.GetStorage(id);

            if (storage == null)
            {
                return(HttpNotFound());
            }

            var viewModel = new StorageFormViewModel()
            {
                Storage   = storage,
                Locations = unitOfWork.Locations.GetLocations()
            };

            return(View("StorageForm", viewModel));
        }
예제 #4
0
        public ActionResult Form(StorageFormCheckedViewModel checkd)
        {
            var storages = context.Storage.ToList();

            var manufacturers = storages.OrderBy(a => a.Manufacturer.Name)
                                .Select(a => a.Manufacturer.Name)
                                .Distinct().ToList();

            var types = storages.OrderBy(a => a.Type)
                        .Select(a => a.Type)
                        .Distinct().ToList();

            var interfaces = context.Interface.OrderBy(a => a.Name)
                             .Select(a => a.Name)
                             .ToList();

            List <string> emptyList = new List <string> {
                ""
            };

            if (checkd.ManufacturersChecked == null)
            {
                checkd.ManufacturersChecked = emptyList;
            }
            if (checkd.InterfaceChecked == null)
            {
                checkd.InterfaceChecked = emptyList;
            }
            if (checkd.TypeChecked == null)
            {
                checkd.TypeChecked = emptyList;
            }

            var storageFormViewModel = new StorageFormViewModel()
            {
                Manufacturers = manufacturers,
                Storages      = storages,
                Types         = types,
                Interfaces    = interfaces,
                StorageFormCheckedViewModel = checkd
            };

            return(PartialView("_Form", storageFormViewModel));
        }