//GET
        public ActionResult Edit(int id)
        {
            var dbItem = _carOptionManager.GetById(id);

            if (dbItem == null)
            {
                throw new NullReferenceException();
            }
            return(View(_carOptionFieldCopier.CopyFields(dbItem, new CarOptionViewModel())));
        }
Exemple #2
0
        public ActionResult Details(int id)
        {
            var dbItem = _carItemManager.GetById(id);

            if (dbItem == null)
            {
                throw new NullReferenceException();
            }

            var result = _carItemFieldCopier.CopyFields(dbItem, new CarItemViewModel());

            if (result.SelectedCarOptions != null)
            {
                for (var i = 0; i < result.SelectedCarOptions.Length; i++)
                {
                    result.SelectedCarOptions[i] = _carOptionsManager.GetById(int.Parse(result.SelectedCarOptions[i])).Name;
                }
            }
            foreach (var image in dbItem.CarImages)
            {
                var img = _carImageFieldCopier.CopyFields(image, new CarImageViewModel());
                img.Data = image.Data;
                result.Images.Add(img);
            }
            return(View(result));
        }
        public CarItem CopyFields(CarItemViewModel from, CarItem to)
        {
            if (to == null)
            {
                throw new NullReferenceException();
            }
            if (from == null)
            {
                throw new NullReferenceException();
            }
            to.BodyTypeId  = from.BodyTypeId;
            to.ModelId     = from.ModelId;
            to.Description = from.Description;
            to.OwnerId     = from.OwnerId;

            to.CarOption.Clear();
            if (from.SelectedCarOptions != null)
            {
                foreach (var s in @from.SelectedCarOptions)
                {
                    int id;
                    if (int.TryParse(s, out id))
                    {
                        to.CarOption.Add(_carOptionManager.GetById(id));
                    }
                }
            }
            to.EditDate          = from.EditDate;
            to.LastEditorId      = from.LastEditorId;
            to.FuelTypeId        = from.FuelTypeId;
            to.TransmitionTypeId = from.TransmitionTypeId;
            to.Price             = from.Price;
            to.Volume            = from.Volume;
            to.Status            = (int)from.Status;
            to.ReleaseYear       = from.ReleaseYear;
            return(to);
        }