Example #1
0
        public virtual ActionResult Edit(MaintainModelViewModel viewModel)
        {
            using (var trans = new TransactionScope())
            {
                using (var context = new TTTEntities())
                {
                    var model = context.refmodels.Where(a => a.ID == viewModel.ModelID).Single();
                    var modelColourDesc = context.lnkmodelcolourdescs.Where(a => a.ID == viewModel.ModelColourDescID).Single();
                    var brandID = context.refbrands.Where(a => a.Name == viewModel.BrandName && a.CategoryID == viewModel.CategoryID).Single().ID;

                    // Model details****************************************************
                    model.BrandID = brandID;
                    model.Price = viewModel.Price;
                    model.DiscountPrice = viewModel.DiscountPrice;
                    // *****************************************************************

                    // Model colour description details*****************************************
                    modelColourDesc.Active = viewModel.Active;
                    modelColourDesc.SKU = viewModel.SKU;
                    modelColourDesc.HeelHeight = viewModel.HeelHeight;
                    modelColourDesc.Style = viewModel.Style;
                    modelColourDesc.Description = viewModel.Description;
                    modelColourDesc.LiningSock = viewModel.LiningSock;
                    modelColourDesc.Sole = viewModel.Sole;
                    modelColourDesc.Make = viewModel.Make;
                    modelColourDesc.UpperMaterial = viewModel.UpperMaterial;
                    modelColourDesc.HeelDesc = viewModel.HeelDesc;
                    // ***************************************************************************

                    // Model lifestyle************************************************************
                    var selectedLifestyleIDs = viewModel.SelectedLifestyleIDText.Replace(",,",",").Split(',').Select(int.Parse).ToList();
                    var selectedLifeStyles = context.reflifestyles.Where(a => selectedLifestyleIDs.Contains(a.ID)).ToList();
                    var modelLifestyles = context.lnkmodellifestyles.Where(a => a.ModelID == viewModel.ModelID &&
                                                                           a.ColourDescID == viewModel.ColourDescID).ToList();
                    modelLifestyles.ForEach(a => { a.Active = false; a.UpdateDT = DateTime.Now; });

                    foreach (var lifeStyle in selectedLifeStyles)
                    {
                        var modelLifestyle = modelLifestyles.Where(a => a.LifeStyleID == lifeStyle.ID).SingleOrDefault();

                        if (modelLifestyle != null)
                        {
                            modelLifestyle.Active = true;
                            modelLifestyle.UpdateDT = DateTime.Now;
                        }
                        else
                        {
                            context.lnkmodellifestyles.Add(new lnkmodellifestyle()
                            {
                                 ColourDescID = viewModel.ColourDescID,
                                 ModelID = viewModel.ModelID,
                                 Active=true,
                                 CreateDT=DateTime.Now,
                                 LifeStyleID=lifeStyle.ID,
                            }); 
                        }
                    }
                    //********************************************************************************

                    // Model trend********************************************************************************
                    var selectedTrendIDs = viewModel.SelectedTrendIDText.Replace(",,", ",").Split(',').Select(int.Parse).ToList();
                    var selectedTrends = context.reftrends.Where(a => selectedTrendIDs.Contains(a.ID)).ToList();
                    var modelTrends = context.lnkmodeltrends.Where(a => a.ModelID == viewModel.ModelID &&
                                                                        a.ColourDescID == viewModel.ColourDescID).ToList();
                    modelTrends.ForEach(a => { a.Active = false; a.UpdateDT = DateTime.Now; });

                    foreach (var trend in selectedTrends)
                    {
                        var modelTrend = modelTrends.Where(a => a.TrendID == trend.ID).SingleOrDefault();

                        if (modelTrend != null)
                        {
                            modelTrend.Active = true;
                            modelTrend.UpdateDT = DateTime.Now;
                        }
                        else
                        {
                            context.lnkmodeltrends.Add(new lnkmodeltrend()
                            {
                                ColourDescID = viewModel.ColourDescID,
                                ModelID = viewModel.ModelID,
                                Active = true,
                                CreateDT = DateTime.Now,
                                TrendID = trend.ID,
                            });
                        }
                    }
                    // ************************************************************************************************

                    context.SaveChanges();
                }

                trans.Complete();
            }

            return RedirectToAction("Edit", new { id = viewModel.ModelColourDescID });
        }
Example #2
0
        public virtual ActionResult Create(MaintainModelViewModel viewModel)
        {
            try
            {
                var modelColourDesc = new lnkmodelcolourdesc();

                using (var trans = new TransactionScope())
                {
                    using (var context = new TTTEntities())
                    {
                        var brandID = context.refbrands.Where(a => a.Name == viewModel.BrandName && a.CategoryID == viewModel.CategoryID).Single().ID;

                        // Model details**********************************************************************************

                        var model = new refmodel();
                        if (!string.IsNullOrEmpty(viewModel.NewModelName))
                        {
                            model = new refmodel()
                            {
                                BrandID = brandID,
                                Price = viewModel.Price,
                                DiscountPrice = viewModel.DiscountPrice,
                                CreateDT = DateTime.Now,
                                Active = true,
                                Gender = "Female",
                                Name = viewModel.NewModelName,
                                Description = "-"
                            };

                            context.refmodels.Add(model);
                            context.SaveChanges();
                        }
                        else
                        {
                            model = context.refmodels.Where(a => a.ID == viewModel.ModelID).Single();
                        }

                        //***************************************************************************************************

                        // Model colour description details******************************************************************

                        modelColourDesc = new lnkmodelcolourdesc()
                        {
                            ModelID = model.ID,
                            ColourDescID = viewModel.ColourDescID,
                            Active = viewModel.Active,
                            SKU = viewModel.SKU,
                            HeelHeight = viewModel.HeelHeight,
                            Style = viewModel.Style,
                            Description = viewModel.Description,
                            LiningSock = viewModel.LiningSock,
                            Sole = viewModel.Sole,
                            Make = viewModel.Make,
                            UpperMaterial = viewModel.UpperMaterial,
                            HeelDesc = viewModel.HeelDesc,
                            CreateDT = DateTime.Now
                        };

                        context.lnkmodelcolourdescs.Add(modelColourDesc);
                        context.SaveChanges();

                        // ****************************************************************************************************

                        // Model lifestyle************************************************************
                        var selectedLifestyleIDs = viewModel.SelectedLifestyleIDText.Replace(",,", ",").Split(',').Select(int.Parse).ToList();
                        var selectedLifeStyles = context.reflifestyles.Where(a => selectedLifestyleIDs.Contains(a.ID)).ToList();

                        foreach (var lifeStyle in selectedLifeStyles)
                        {
                            context.lnkmodellifestyles.Add(new lnkmodellifestyle()
                            {
                                ColourDescID = viewModel.ColourDescID,
                                ModelID = model.ID,
                                Active = true,
                                CreateDT = DateTime.Now,
                                LifeStyleID = lifeStyle.ID,
                            });
                        }
                        //********************************************************************************

                        // Model trend********************************************************************************
                        var selectedTrendIDs = viewModel.SelectedTrendIDText.Replace(",,", ",").Split(',').Select(int.Parse).ToList();
                        var selectedTrends = context.reftrends.Where(a => selectedTrendIDs.Contains(a.ID)).ToList();

                        foreach (var trend in selectedTrends)
                        {
                            context.lnkmodeltrends.Add(new lnkmodeltrend()
                            {
                                ColourDescID = viewModel.ColourDescID,
                                ModelID = model.ID,
                                Active = true,
                                CreateDT = DateTime.Now,
                                TrendID = trend.ID,
                            });
                        }
                        // ************************************************************************************************

                        context.SaveChanges();
                    }

                    trans.Complete();
                }

                return RedirectToAction("Edit", new { id = modelColourDesc.ID });
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #3
0
        public virtual ActionResult Edit(int id)
        {
            var maintainViewModel = new MaintainModelViewModel();

            using (var context = new TTTEntities())
            {
                //var results = context.refmodels
                //    .Join(context.refbrands, a => a.BrandID, b => b.ID, (a, b) => new { Model = a, Brand = b })
                //    .Join(context.refcategories, a => a.Brand.CategoryID, b => b.ID, (a, b) => new { ModelBrand = a, Category = b })
                //    .Join(context.lnkmodelcolourdescs, a => a.ModelBrand.Model.ID, b => b.ModelID, (a, b) => new { ModelBrandCategory = a, ModelColourDesc = b })
                //    .Join(context.refcolourdescs, a => a.ModelColourDesc.ColourDescID, b => b.ID, (a, b) => new { ModelBrandCategoryColourDesc = a, ColourDesc = b })
                //    .GroupJoin(context.lnkmodeltrends, a=>a.ModelBrandCategoryColourDesc.ModelBrandCategory.ModelBrand.Model.ID, b=>b.ModelID,
                //            (a, b) => new { ModelBrandCategoryColourDescTrends = a, ModelTrend = b })
                //    .GroupJoin(context.lnkmodellifestyles, a => a.ModelBrandCategoryColourDescTrends.ModelBrandCategoryColourDesc.ModelBrandCategory.ModelBrand.Model.ID, b => b.ModelID,
                //            (a, b) => new { ModelBrandCategoryColourDescTrendLifestyle = a, ModelLifestyle = b })
                //    .Select(a => new
                //    {
                //        Model = a.ModelBrandCategoryColourDescTrendLifestyle.ModelBrandCategoryColourDescTrends.ModelBrandCategoryColourDesc.ModelBrandCategory.ModelBrand.Model,
                //        Brand = a.ModelBrandCategoryColourDescTrendLifestyle.ModelBrandCategoryColourDescTrends.ModelBrandCategoryColourDesc.ModelBrandCategory.ModelBrand.Brand,
                //        Category = a.ModelBrandCategoryColourDescTrendLifestyle.ModelBrandCategoryColourDescTrends.ModelBrandCategoryColourDesc.ModelBrandCategory.Category,
                //        ColourDesc = a.ModelBrandCategoryColourDescTrendLifestyle.ModelBrandCategoryColourDescTrends.ColourDesc,
                //        ModelColourDesc = a.ModelBrandCategoryColourDescTrendLifestyle.ModelBrandCategoryColourDescTrends.ModelBrandCategoryColourDesc.ModelColourDesc,
                //        ModelTrend = a.ModelBrandCategoryColourDescTrendLifestyle.ModelTrend,
                //        ModelLifestyle = a.ModelLifestyle
                //    })
                //    .Where(a => a.ModelColourDesc.ID == id)
                //    .ToList();

                var results = context.lnkmodelcolourdescs
                                     .Join(context.refmodels, a => a.ModelID, b => b.ID, (a, b) => new { ModelColourDesc = a, Model = b })
                                     .Join(context.refcolourdescs, a => a.ModelColourDesc.ColourDescID, b => b.ID,
                                            (a, b) => new { a.ModelColourDesc, a.Model, ColourDesc = b })
                                     .Join(context.refbrands, a => a.Model.BrandID, b => b.ID,
                                            (a, b) => new { a.ModelColourDesc, a.Model, a.ColourDesc, Brand = b })
                                     .Join(context.refcategories, a => a.Brand.CategoryID, b => b.ID,
                                            (a, b) => new { a.ModelColourDesc, a.Model, a.ColourDesc, a.Brand, Category = b })
                                     .GroupJoin(context.lnkmodeltrends, a => new { a.ModelColourDesc.ModelID, a.ModelColourDesc.ColourDescID },
                                            b => new { b.ModelID, b.ColourDescID },
                                            (a, b) => new { a.ModelColourDesc, a.Model, a.ColourDesc, a.Brand, a.Category, ModelTrends = b })
                                     .GroupJoin(context.lnkmodellifestyles, a => new { a.ModelColourDesc.ModelID, a.ModelColourDesc.ColourDescID },
                                            b => new { b.ModelID, b.ColourDescID },
                                            (a, b) => new { a.ModelColourDesc, a.Model, a.ColourDesc, a.Brand, a.Category, a.ModelTrends, ModelLifestyles = b })
                                     .Where(a => a.ModelColourDesc.ID == id)
                                     .ToList();

                var modelDetails = results.First();

                var trendIDs = results.Select(a => a.ModelTrends).First().Count() > 0 ?
                                        results.Select(a => a.ModelTrends).First().Where(b => b.Active).Select(c => c.TrendID).Distinct().ToList() :
                                        new List<int>();
                var lifestyleIDs = results.Select(a => a.ModelLifestyles).First().Count() > 0 ?
                                        results.Select(a => a.ModelLifestyles).First().Where(b => b.Active).Select(c => c.LifeStyleID).Distinct().ToList() :
                                    new List<int>();

                maintainViewModel = new MaintainModelViewModel()
                {
                    ModelColourDescID = id,
                    BrandID = modelDetails.Brand.ID,
                    BrandName = modelDetails.Brand.Name,
                    CategoryID = modelDetails.Category.ID,
                    ModelID = modelDetails.Model.ID,
                    ModelName = modelDetails.Model.Name,
                    ColourDescID = modelDetails.ColourDesc.ID,
                    ColourID = modelDetails.ColourDesc.ColourID,
                    Description = modelDetails.ModelColourDesc.Description,
                    DiscountPrice = modelDetails.Model.DiscountPrice == null ? 0 : modelDetails.Model.DiscountPrice.Value,
                    Price = modelDetails.Model.Price,
                    HeelDesc = modelDetails.ModelColourDesc.HeelDesc,
                    Sole = modelDetails.ModelColourDesc.Sole,
                    LiningSock = modelDetails.ModelColourDesc.LiningSock,
                    Make = modelDetails.ModelColourDesc.Make,
                    Style = modelDetails.ModelColourDesc.Style,
                    UpperMaterial = modelDetails.ModelColourDesc.UpperMaterial,
                    HeelHeight = modelDetails.ModelColourDesc.HeelHeight,
                    SKU = modelDetails.ModelColourDesc.SKU,
                    SelectedTrend = trendIDs,
                    SelectedTrendIDText = string.Format("0,{0}", string.Join(",", trendIDs)),
                    SelectedLifestyle = lifestyleIDs,
                    SelectedLifestyleIDText = string.Format("0,{0}", string.Join(",", lifestyleIDs)),
                    AvailableLifestyles = context.reflifestyles.Where(a => a.Active).ToList(),
                    AvailableTrends = context.reftrends.Where(a => a.Active).ToList(),
                    Active = modelDetails.Model.Active
                };
            }

            return View(maintainViewModel);

        }
Example #4
0
        public virtual ActionResult Create()
        {
            var maintainViewModel = new MaintainModelViewModel();

            using (var context = new TTTEntities())
            {
                maintainViewModel = new MaintainModelViewModel()
                {
                    SelectedTrendIDText = "0",
                    SelectedLifestyleIDText = "0",
                    AvailableLifestyles = context.reflifestyles.Where(a=>a.Active).ToList(),
                    AvailableTrends = context.reftrends.Where(a => a.Active).ToList(),
                };
            }

            return View(maintainViewModel);

        }