Esempio n. 1
0
        public virtual ActionResult Size(ModelSizeViewModel viewModel, FormCollection collection)
        {
            using (var trans = new TransactionScope())
            {
                using (var context = new TTTEntities())
                {
                    var modelSizes = context.lnkmodelsizes
                                           .Where(a => a.ModelID == viewModel.ModelID && a.ColourDescID == viewModel.ColourDescID)
                                           .ToList();

                    var beginSize = Convert.ToInt16((Properties.Settings.Default.InitialSize.Split(',')[0]).Split('|')[0]);
                    var sizeRange = Convert.ToInt16((Properties.Settings.Default.InitialSize.Split(',')[1]));

                    for (var i = beginSize; i <= beginSize + sizeRange; i++)
                    {
                        var modelSize = modelSizes.Where(a => a.Size == i.ToString()).SingleOrDefault();

                        if (modelSize == null)
                        {
                            context.lnkmodelsizes.Add(new lnkmodelsize()
                            {
                                ModelID = viewModel.ModelID,
                                ColourDescID = viewModel.ColourDescID,
                                Active = true,
                                CreateDT = DateTime.Now,
                                Size = i.ToString(),
                                Quantity = Convert.ToInt32(collection[string.Format("txt_{0}", i.ToString())])
                            });
                        }
                        else
                        {
                            modelSize.Quantity = Convert.ToInt32(collection[string.Format("txt_{0}", modelSize.Size)]);
                            modelSize.UpdateDT = DateTime.Now;
                        }
                    }

                    context.SaveChanges();
                }

                trans.Complete();
            }

            return RedirectToAction("Edit", new { id = viewModel.ModelColourDescID });
        }
Esempio n. 2
0
        public virtual ActionResult Size(int modelID, int colourDescID)
        {
            var modelSizeViewModel = new ModelSizeViewModel()
            {
                ModelID = modelID,
                ColourDescID = colourDescID
            };

            using (var context = new TTTEntities())
            {
                modelSizeViewModel.ModelSizes = context.lnkmodelsizes.Where(a => a.ModelID == modelID && a.ColourDescID == colourDescID).ToList();
                modelSizeViewModel.ModelColourDescID = context.lnkmodelcolourdescs.Where(a => a.ModelID == modelID && a.ColourDescID == colourDescID).First().ID;
            }

            //35|5|2|4,8
            var beginSize = Convert.ToInt16((Properties.Settings.Default.InitialSize.Split(',')[0]).Split('|')[0]);
            var sizeRange = Convert.ToInt16((Properties.Settings.Default.InitialSize.Split(',')[1]));

            for (var i = beginSize; i <= beginSize + sizeRange; i++)
                modelSizeViewModel.AvailableSize.Add(i.ToString());

            return View(modelSizeViewModel);
        }