Beispiel #1
0
        private InstrumentEditViewModel LoadInstrumentEditViewModel(int productId)
        {
            var product    = GetInstrumentProduct(productId);
            var instrument = product.Instrument;

            var vm = new InstrumentEditViewModel
            {
                Id        = instrument.Id,
                ProductId = productId,

                Price          = product.Price,
                DisplayPrice   = product.DisplayPrice,
                IsPosted       = product.IsPosted,
                DefaultPhotoId = product.GetDefaultPhotoId(),
                MaxImageWidth  = InstrumentImageSizeEdit.Width,
                MaxImageHeight = InstrumentImageSizeEdit.Height,

                Model        = instrument.Model,
                Sn           = instrument.Sn,
                Top          = instrument.Top,
                BackAndSides = instrument.BackAndSides,
                Body         = instrument.Body,
                Binding      = instrument.Binding,
                Bridge       = instrument.Bridge,
                CaseDetail   = instrument.CaseDetail,
                Dimensions   = instrument.Dimensions,
                EdgeDots     = instrument.EdgeDots,
                Faceplate    = instrument.Faceplate,
                Finish       = instrument.Finish,
                Fingerboard  = instrument.Fingerboard,
                FretMarkers  = instrument.FretMarkers,
                FretWire     = instrument.FretWire,
                Neck         = instrument.Neck,
                NutWidth     = instrument.NutWidth,
                PickGuard    = instrument.PickGuard,
                Pickup       = instrument.Pickup,
                ScaleLength  = instrument.ScaleLength,
                Strings      = instrument.Strings,
                Tailpiece    = instrument.Tailpiece,
                Tuners       = instrument.Tuners,

                Comments = instrument.Comments,
                FunFacts = instrument.FunFacts,

                InstrumentTypes  = new SelectList(_instrumentTypes.GetAll(), "Id", "InstrumentTypeDesc", instrument.InstrumentType.Id),
                InstrumentTypeId = instrument.InstrumentType.Id,

                ClassificationTypes = new SelectList(_classifications.GetAll(), "Id", "ClassificationDesc", instrument.Classification.Id),
                ClassificationId    = instrument.Classification.Id,

                SubClassificationTypes = new SelectList(_subClassifications.GetAll(), "Id", "SubClassificationDesc", instrument.SubClassification.Id),
                SubClassificationId    = instrument.SubClassification.Id,

                StatusTypes = new SelectList(_productStatus.GetAll(), "Id", "StatusDesc", product.ProductStatus.Id),
                StatusId    = product.ProductStatus.Id
            };

            return(vm);
        }
Beispiel #2
0
        public ActionResult Edit(int id, InstrumentEditViewModel viewModel)
        {
            var product = _products.Get(id);

            UpdateProductInstrument(product, viewModel);

            return(RedirectToAction("Index", "Instrument"));
        }
Beispiel #3
0
        private void AddInstrument(InstrumentEditViewModel viewModel)
        {
            var product = new Product
            {
                ProductType = new ProductType {
                    Id = 1
                },
                Instrument = new Instrument
                {
                    InstrumentType = new InstrumentType {
                        Id = viewModel.InstrumentTypeId
                    },
                    Classification = new Classification {
                        Id = viewModel.ClassificationId
                    },
                    SubClassification = new SubClassification {
                        Id = viewModel.SubClassificationId
                    },

                    Top          = viewModel.Top,
                    Body         = viewModel.Body,
                    BackAndSides = viewModel.BackAndSides,
                    Binding      = viewModel.Binding,
                    Bridge       = viewModel.Bridge,
                    CaseDetail   = viewModel.CaseDetail,
                    Comments     = viewModel.Comments,
                    Dimensions   = viewModel.Dimensions,
                    EdgeDots     = viewModel.EdgeDots,
                    Faceplate    = viewModel.Faceplate,
                    Fingerboard  = viewModel.Fingerboard,
                    Finish       = viewModel.Finish,
                    FretMarkers  = viewModel.FretMarkers,
                    FretWire     = viewModel.FretWire,
                    FunFacts     = viewModel.FunFacts,
                    Model        = viewModel.Model,
                    Neck         = viewModel.Neck,
                    NutWidth     = viewModel.NutWidth,
                    PickGuard    = viewModel.PickGuard,
                    Pickup       = viewModel.Pickup,
                    ScaleLength  = viewModel.ScaleLength,
                    Sn           = viewModel.Sn,
                    Tailpiece    = viewModel.Tailpiece,
                    Tuners       = viewModel.Tuners
                },
                ProductDesc   = "Instrument",
                Price         = viewModel.Price,
                DisplayPrice  = viewModel.DisplayPrice,
                ProductStatus = new ProductStatus {
                    Id = viewModel.StatusId
                },
                IsPosted = false
            };

            _products.Add(product);
        }
        private InstrumentEditViewModel LoadInstrumentEditViewModel(int id)
        {
            Instrument instrument = null;

            if (id > 0)
            {
                instrument = _instrumentRepository.Get(id);
            }
            var vm = new InstrumentEditViewModel
            {
                Name         = (instrument != null) ? instrument.Name : string.Empty,
                Abbreviation = (instrument != null) ? instrument.Abbreviation : string.Empty
            };

            return(vm);
        }
Beispiel #5
0
        private void UpdateProductInstrument(Product product, InstrumentEditViewModel viewModel)
        {
            var posted   = viewModel.IsPosted;
            var statusid = viewModel.StatusId;

            if (product.ProductStatus.Id != statusid)
            {
                product.ProductStatus = _productStatus.GetAll().Single(x => x.Id == statusid);
            }
            product.ProductStatus.Id = viewModel.StatusId;
            product.IsPosted         = posted;
            product.Price            = viewModel.Price;
            product.DisplayPrice     = viewModel.DisplayPrice;
            UpdateInstrument(product.Instrument, viewModel);
            _products.Update(product);
        }
Beispiel #6
0
        private void UpdateInstrument(Instrument instrument, InstrumentEditViewModel viewModel)
        {
            if (instrument.InstrumentType.Id != viewModel.InstrumentTypeId)
            {
                instrument.InstrumentType = _instrumentTypes.GetAll().Single(x => x.Id == viewModel.InstrumentTypeId);
            }

            if (instrument.Classification.Id != viewModel.ClassificationId)
            {
                instrument.Classification = _classifications.GetAll().Single(x => x.Id == viewModel.ClassificationId);
            }

            if (instrument.SubClassification.Id != viewModel.SubClassificationId)
            {
                instrument.SubClassification = _subClassifications.GetAll().Single(x => x.Id == viewModel.SubClassificationId);
            }

            instrument.Top          = viewModel.Top;
            instrument.BackAndSides = viewModel.BackAndSides;
            instrument.Binding      = viewModel.Binding;
            instrument.Body         = viewModel.Body;
            instrument.Bridge       = viewModel.Bridge;
            instrument.CaseDetail   = viewModel.CaseDetail;
            instrument.Comments     = viewModel.Comments;
            instrument.Dimensions   = viewModel.Dimensions;
            instrument.EdgeDots     = viewModel.EdgeDots;
            instrument.Faceplate    = viewModel.Faceplate;
            instrument.Fingerboard  = viewModel.Fingerboard;
            instrument.Finish       = viewModel.Finish;
            instrument.FretMarkers  = viewModel.FretMarkers;
            instrument.FretWire     = viewModel.FretWire;
            instrument.FunFacts     = viewModel.FunFacts;
            instrument.Model        = viewModel.Model;
            instrument.Neck         = viewModel.Neck;
            instrument.NutWidth     = viewModel.NutWidth;
            instrument.PickGuard    = viewModel.PickGuard;
            instrument.Pickup       = viewModel.Pickup;
            instrument.ScaleLength  = viewModel.ScaleLength;
            instrument.Sn           = viewModel.Sn;
            instrument.Strings      = viewModel.Strings;
            instrument.Tailpiece    = viewModel.Tailpiece;
            instrument.Tuners       = viewModel.Tuners;
        }
Beispiel #7
0
        public ActionResult Delete(int id, InstrumentEditViewModel viewModel)
        {
            _products.Delete(id);

            return(RedirectToAction("Index"));
        }
Beispiel #8
0
        public ActionResult Create(InstrumentEditViewModel viewModel)
        {
            AddInstrument(viewModel);

            return(RedirectToAction("Index"));
        }