Beispiel #1
0
        public IActionResult ChooseStyle(/*int eventId*/)//have to add choose event to this rather than taking in an event as a parameter.
        {
            var model = new ChooseStyleForNewProductKit_ViewModel();

            //List<int> styleIdsALreadyAssociatedWIthThisEvent = new List<int>();//will be able to take out this whole section and allow creation of lots of productkits for a given event and style
            //var productKitsAlreadyAssociatedWithThisEvent = _context.ProductKit.Where(pk => pk.EventId == eventId);
            //if (productKitsAlreadyAssociatedWithThisEvent != null)
            //{
            //    foreach (var productKit in productKitsAlreadyAssociatedWithThisEvent)
            //    {
            //        styleIdsALreadyAssociatedWIthThisEvent.Add(productKit.StyleId);
            //    }
            //}
            //&& !styleIdsALreadyAssociatedWIthThisEvent.Contains(t.Id)//was in where for styles

            var events = _context.Event.OrderBy(c => c.Name).Where(t => t.IsActive == true).Select(x => new { Id = x.Id, Value = x.Name });

            model.EventList = new SelectList(events, "Id", "Value");

            //not sure if bellow && not section is working
            var styles = _context.Style.OrderBy(c => c.Name).Where(t => t.IsActive == true).Select(x => new { Id = x.Id, Value = x.Name });

            model.StyleList = new SelectList(styles, "Id", "Value");

            var territories = _context.Territory.OrderBy(c => c.Name).Where(t => t.IsActive == true).Select(x => new { Id = x.Id, Value = x.Name });

            model.TerritoryList = new SelectList(territories, "Id", "Value");

            //c.	What if you make the same style id on the same event multiple times? The dropdown needs to not populate with all styles,
            //but only styles that are not already associated with this event

            //model.EventId = eventId;

            return(View(model));
        }
Beispiel #2
0
        // GET: ProductKits/Create
        public IActionResult CreateGet(ChooseStyleForNewProductKit_ViewModel chooseModel, int evntId) //need to set the routing up to pass this in on create like you normally do on an edit, and that create button needs to be on an event details page,
        {                                                                                             //but where will the checkout page be? perhaps on event, details as well, and then press a button for check in and check out
            //style id will have to come from a dropdown
            var model = new ProductKit_ViewModel();

            model.EventId     = chooseModel.EventId;//maybe this works instead of above
            model.StyleId     = chooseModel.StyleId;
            model.TerritoryId = chooseModel.TerritoryId;

            //im still passing in evntId even though I don't need to so that routing knows to choose this method instead of the create post method because the only difference is the signature parameters
            //styleId isn't getting passed in from choose style

            string eventName = "";
            var    evnt      = _context.Event.FirstOrDefault(e => e.Id == model.EventId);

            if (evnt != null)
            {
                eventName = evnt.Name;
            }

            string styleName = "";
            var    style     = _context.Style.FirstOrDefault(s => s.Id == model.StyleId);

            if (style != null)
            {
                styleName = style.Name;
            }

            string territoryName = "";
            var    territory     = _context.Territory.FirstOrDefault(s => s.Id == model.TerritoryId);

            if (territory != null)
            {
                territoryName = territory.Name;
            }

            styleName     = styleName.Replace(" ", "-");
            territoryName = territoryName.Replace(" ", "-");
            eventName     = eventName.Replace(" ", "-");

            //


            if (style != null && evnt != null && territory != null) //wait no the identifier has to take into account the style and territory combination
            {
                model.Name = styleName + "-" + territoryName;       //* + "-" + idToUse.Identifier*/;//last part moved to post
                //* + "-" + existingProductKitsForThisStyleAndTerritory.Count*/;//here i need to start adding the identifiers, need to go through all existing product kits
                //with both this style and this terriotry and increment up once for each entry, not sure how above works out if/when i start deleting product kits, the count shoule
                //workout i think
            }
            else
            {
                model.Name = "Unnamed Product Kit";
            }

            var productsList = _context.Product.Where(s => s.StyleId == model.StyleId).ToList();

            productsList       = productsList.OrderBy(p => p.SizeId).ToList();//ADDED FOR ORDER test to make sure it does not throw off alignemnt in for loops with name
            model.ProductIds   = new List <int>();
            model.ProductNames = new List <string>();

            foreach (var product in productsList)
            {
                model.ProductNames.Add(product.Name);
                model.ProductIds.Add(product.Id);
            }
            model.Quantities = new int[model.ProductNames.Count];
            for (int i = 0; i < model.Quantities.Length; i++)
            {
                model.Quantities[i] = 1;
            }
            model.QuantitiesAvailable = new int[model.ProductNames.Count];


            return(View(model));
        }