Ejemplo n.º 1
0
        public async Task<ActionResult> Edit(ItemRegistrationModel model)
        {
            cfcusaga.data.Cart cartItem;
            cfcusaga.data.Item item;
            if (ModelState.IsValid)
            {
                cartItem = await _db.Carts.FindAsync(model.CartID);
                item = await _db.Items.FindAsync(cartItem.ItemId);

                var entity = _db.CartItemRegistrations.Find(model.ID);

                entity.LastName = model.LastName;
                entity.FirstName = model.FirstName;
                if (item.IsRequireBirthDateInfo.HasValue && item.IsRequireBirthDateInfo.Value)
                {
                    entity.BirthDate = model.BirthDate;
                }
                
                entity.RelationToMemberTypeId = model.RelationToMemberTypeId;
                entity.Gender = model.Gender;
                entity.Allergies = model.Allergies;
                if (model.TshirtSize != null)
                {
                    entity.TshirtSize = model.TshirtSize;
                }
                _db.Entry(entity).State = EntityState.Modified;

                await _db.SaveChangesAsync();
                return RedirectToAction("Index", "ShoppingCart");
            }

            cartItem = await _db.Carts.FindAsync(model.CartID);

            item = await _db.Items.FindAsync(cartItem.ItemId);
            ViewBag.SubTitle = item.Name;
            ViewBag.ItemId = item.ID;
            ViewBag.IsRequireBirthDate = item.IsRequireBirthDateInfo ?? false;
            ViewBag.IsRequireParentWaiver = item.IsRequireParentWaiver ?? false;
            ViewBag.IsShirtIncluded = item.IsShirtIncluded ?? false;

            SelectList relationTypesList = null;
            if (item.IsRequireParentWaiver != null && item.IsRequireParentWaiver.Value)
            {
                var relationTypes = _eventSvc.GetRelationToMemberTypesRequiresParentWaiver();
                relationTypesList = new SelectList(relationTypes, "Id", "Name");
            }
            else
            {
                var sessionInfo = ItemRegistrationsController.GetSessionCurrentRegistrationInfo(this.HttpContext);
                //relationTypes = _svc.GetRelationToMemberTypesAdults();
                var relationTypes = _eventSvc.GetRelationToMemberTypesAdults().ToList();
                IEnumerable<RelationToMemberType> selectListItems = null;
                //newRegistratinItem.RelationToMemberTypes = new SelectList(relationTypes, "Id", "Name");
                if (sessionInfo != null && sessionInfo.IsSelfSelected)
                {
                    selectListItems = relationTypes.Where(m => m.Name.ToUpper() != "SELF");
                }
                else
                {
                    selectListItems = relationTypes.ToList();
                }
                relationTypesList = new SelectList(selectListItems, "Id", "Name");
            }

            var list = GetTShirtSizesList();
            ViewBag.TshirtSizes = list;
            model.RelationToMemberTypes = relationTypesList;
            return View(model);
        }
Ejemplo n.º 2
0
        public async Task<ActionResult> Create(ItemRegistrationModel itemRegistration)
        {
            var itemId = Convert.ToInt32(Request.QueryString["itemId"]);
            if (ModelState.IsValid)
            {
                //TODO:
                

                var foundItem = await _cartSvc.GetItem(itemId);

                var cart = ShoppingCart.GetCart(this.HttpContext, _cartSvc);
                int count;
                var currentCart =  cart.AddToCart(foundItem, out count);
                

                ItemRegistrationsController.SetSessionCurrentRegistrationInfo(this.HttpContext, itemRegistration.LastName, string.Empty);
                //var eventId = EventsController.GetSessionEventId(this.HttpContext);

                itemRegistration.CartID = currentCart.Id;

                if (itemRegistration.RelationToMemberTypeId != null && itemRegistration.RelationToMemberTypeId == (int)Enums.RelationToMe.Self)
                {
                    ItemRegistrationsController.SetSessionCurrentRegistrationInfo(this.HttpContext, itemRegistration.LastName, itemRegistration.FirstName, true, itemRegistration.Gender);
                    var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
                    if (user != null)
                    {
                        var aMember = await GetMember(user.Id);
                        if (aMember != null)
                        {
                            itemRegistration.MemberId = aMember.Id;
                            itemRegistration.LastName = aMember.LastName;
                            itemRegistration.FirstName = aMember.Firstname;
                            itemRegistration.Gender = aMember.Gender;
                        }
                    }
                }

                using (var dbContextTransaction = _db.Database.BeginTransaction())
                {
                    try
                    {
                        var cartItem = _db.CartItemRegistrations.Create();
                        cartItem.CartID = itemRegistration.CartID;
                        cartItem.Allergies = itemRegistration.Allergies;
                        cartItem.BirthDate = itemRegistration.BirthDate;
                        cartItem.FirstName = itemRegistration.FirstName;
                        cartItem.Gender = itemRegistration.Gender;
                        cartItem.LastName = itemRegistration.LastName;
                        cartItem.MemberId = itemRegistration.MemberId;
                        cartItem.RelationToMemberTypeId = itemRegistration.RelationToMemberTypeId;
                        cartItem.TshirtSize = itemRegistration.TshirtSize;
                        _db.CartItemRegistrations.Add(cartItem);
                        //await _db.SaveChangesAsync();

                        await AddItemDiscount(foundItem, currentCart);
                        await _db.SaveChangesAsync();

                        dbContextTransaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        var msg = ex.Message;
                        dbContextTransaction.Rollback();
                        throw;
                    }
                }



                return RedirectToAction("Index", "Items" );
            }
            //


            var item = await _db.Items.FindAsync(itemId);
            ViewBag.SubTitle = item.Name;
            ViewBag.ItemId = itemId;
            ViewBag.IsRequireBirthDate = item.IsRequireBirthDateInfo ?? false;
            ViewBag.IsRequireParentWaiver = item.IsRequireParentWaiver ?? false;
            ViewBag.IsShirtIncluded = item.IsShirtIncluded ?? false;

            var list = GetTShirtSizesList();
            ViewBag.TshirtSizes = list;


            var sessionInfo = ItemRegistrationsController.GetSessionCurrentRegistrationInfo(this.HttpContext);
            //var newRegistratinItem = new ItemRegistrationModel();
            itemRegistration.IsBirthDateRequired = item.IsRequireBirthDateInfo ?? false;
            //itemRegistration.Gender = "M";

            if (item.IsRequireParentWaiver != null && item.IsRequireParentWaiver.Value)
            {
                var relationTypes = _eventSvc.GetRelationToMemberTypesRequiresParentWaiver();
                itemRegistration.RelationToMemberTypes = new SelectList(relationTypes, "Id", "Name");
            }
            else
            {
                var relationTypes = _eventSvc.GetRelationToMemberTypesAdults().ToList();
                IEnumerable<RelationToMemberType> selectListItems = null;
                //newRegistratinItem.RelationToMemberTypes = new SelectList(relationTypes, "Id", "Name");
                if (sessionInfo != null && sessionInfo.IsSelfSelected)
                {
                    selectListItems = relationTypes.Where(m => m.Name.ToUpper() != "SELF");
                    itemRegistration.Gender = sessionInfo.Gender == "F" ? "M" : "F";//TODO: need to make gender an Enum
                }
                else
                {
                    selectListItems = relationTypes.ToList();
                }
                var relationTypesList = new SelectList(selectListItems, "Id", "Name");
                itemRegistration.RelationToMemberTypes = relationTypesList;
            }



            return View(itemRegistration);
        }
Ejemplo n.º 3
0
        // GET: ItemRegistrations/Edit/5
        public async Task<ActionResult> Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            var itemRegistration = await _db.CartItemRegistrations.FindAsync(id);
            if (itemRegistration == null)
            {
                return HttpNotFound();
            }

            //ViewBag.RelationToMemberTypeId = new SelectList(_svc.GetRelationToMemberTypes(), "Id", "Name");

            var eventId = EventsController.GetSessionEventId(this.HttpContext);
            if (eventId == null)
            {
                if (itemRegistration.Cart.Item.EventId != null)
                {
                    eventId = itemRegistration.Cart.Item.EventId;
                    EventsController.SetSessionEventId(this.HttpContext, eventId.Value);
                }

            }
            var anEvent = await _eventSvc.GetEventDetails(eventId);
            ViewBag.Title = anEvent.Name;
            var cartItem = await _db.Carts.FindAsync(itemRegistration.CartID);

            var item = await _db.Items.FindAsync(cartItem.ItemId);
            ViewBag.SubTitle = item.Name;
            ViewBag.ItemId = item.ID;
            ViewBag.IsRequireBirthDate = item.IsRequireBirthDateInfo ?? false;
            ViewBag.IsRequireParentWaiver = item.IsRequireParentWaiver ?? false;
            ViewBag.IsShirtIncluded = item.IsShirtIncluded ?? false;

            var sessionInfo = ItemRegistrationsController.GetSessionCurrentRegistrationInfo(this.HttpContext);

            
            //IEnumerable relationTypes;
            SelectList relationTypesList = null;
            if (item.IsRequireParentWaiver != null && item.IsRequireParentWaiver.Value)
            {
                var relationTypes = _eventSvc.GetRelationToMemberTypesRequiresParentWaiver();
                relationTypesList = new SelectList(relationTypes, "Id", "Name");
            }
            else
            {
                 //relationTypes = _svc.GetRelationToMemberTypesAdults();
                var relationTypes = _eventSvc.GetRelationToMemberTypesAdults().ToList();
                IEnumerable<RelationToMemberType> selectListItems = null;
                //newRegistratinItem.RelationToMemberTypes = new SelectList(relationTypes, "Id", "Name");
                if (sessionInfo != null && sessionInfo.IsSelfSelected)
                {
                    selectListItems = relationTypes.Where(m => m.Name.ToUpper() != "SELF");
                }
                else
                {
                    selectListItems = relationTypes.ToList();
                }
                relationTypesList = new SelectList(selectListItems, "Id", "Name");
            }

            var list = GetTShirtSizesList();
            ViewBag.TshirtSizes = list;

            var itemRegModel = new ItemRegistrationModel()
            {
                LastName = itemRegistration.LastName,
                MemberId = itemRegistration.MemberId,
                FirstName = itemRegistration.FirstName,
                BirthDate = itemRegistration.BirthDate,
                RelationToMemberTypeId = itemRegistration.RelationToMemberTypeId,
                Gender = itemRegistration.Gender,
                TshirtSize = itemRegistration.TshirtSize,
                Allergies = itemRegistration.Allergies,
                ID = itemRegistration.ID,
                CartID = itemRegistration.CartID,
                RelationToMemberTypes = relationTypesList, //new SelectList(relationTypes, "Id", "Name")
                IsBirthDateRequired = item.IsRequireBirthDateInfo ?? false
            };

            return View(itemRegModel);
        }
Ejemplo n.º 4
0
        // GET: ItemRegistrations/Create
        public async Task<ActionResult> Create(int itemId)
        {
            //ViewBag.RelationToMemberTypeId = new SelectList(_svc.GetRelationToMemberTypes(), "ID", "Name");

            var eventId= EventsController.GetSessionEventId(this.HttpContext);
            var anEvent = await _eventSvc.GetEventDetails(eventId);
            ViewBag.Title = anEvent.Name;
            var item = await _db.Items.FindAsync(itemId);
            ViewBag.SubTitle = item.Name;
            ViewBag.ItemId = itemId;
            ViewBag.IsRequireBirthDate = item.IsRequireBirthDateInfo ?? false;
            ViewBag.IsRequireParentWaiver = item.IsRequireParentWaiver ?? false;
            ViewBag.IsShirtIncluded = item.IsShirtIncluded ?? false;

            var list = GetTShirtSizesList();
            ViewBag.TshirtSizes = list;


            var sessionInfo = ItemRegistrationsController.GetSessionCurrentRegistrationInfo(this.HttpContext);
            var newRegistratinItem = new ItemRegistrationModel();
            newRegistratinItem.IsBirthDateRequired = item.IsRequireBirthDateInfo ?? false;
            newRegistratinItem.Gender = "M";

            if (item.IsRequireParentWaiver != null && item.IsRequireParentWaiver.Value)
            {
                var relationTypes = _eventSvc.GetRelationToMemberTypesRequiresParentWaiver();
                newRegistratinItem.RelationToMemberTypes = new SelectList(relationTypes, "Id", "Name");
            }
            else
            {
                var relationTypes = _eventSvc.GetRelationToMemberTypesAdults().ToList();
                IEnumerable<RelationToMemberType> selectListItems = null;
                //newRegistratinItem.RelationToMemberTypes = new SelectList(relationTypes, "Id", "Name");
                if (sessionInfo != null && sessionInfo.IsSelfSelected)
                {
                    selectListItems = relationTypes.Where(m => m.Name.ToUpper() != "SELF");
                    newRegistratinItem.Gender = sessionInfo.Gender=="F"?"M":"F";//TODO: need to make gender an Enum
                }
                else
                {
                    selectListItems = relationTypes.ToList();
                }
                var relationTypesList = new SelectList(selectListItems, "Id", "Name");
                newRegistratinItem.RelationToMemberTypes = relationTypesList;
            }

            if (sessionInfo != null)
            {
                newRegistratinItem.LastName = sessionInfo.Lastname;
            }
            ViewBag.RelationToMemberTypes = newRegistratinItem.RelationToMemberTypes;
            return View(newRegistratinItem);
        }