Example #1
0
        public async Task <IActionResult> Create([Bind("pricePuppyID,PricePuppyDesc,pricePuppy,pricePuppyImageUrl")] PricingPuppyModel pricingPuppyModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(pricingPuppyModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(pricingPuppyModel));
        }
Example #2
0
        public async Task <IActionResult> Create([Bind("TrainerId,TrainerName,TrainerArea,DogNumber")] TrainersModel trainersModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(trainersModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(trainersModel));
        }
        public async Task <IActionResult> Create([Bind("trainingServicesPriceID,trainingName,priceTraining,trainingDesc")] TrainingServicesPriceModel trainingServicesPriceModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(trainingServicesPriceModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(trainingServicesPriceModel));
        }
        public async Task <IActionResult> Create([Bind("TrainingId,DogName,TrainerId,GraduationDate,TrainingType")] TrainingDogModel trainingDogModel)
        {
            if (ModelState.IsValid)
            {
                _context.Add(trainingDogModel);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(trainingDogModel));
        }
Example #5
0
        public async Task <IActionResult> UpdateAccount(string userId, string selectRole)
        {
            var user = await _context.IdentityUser.FindAsync(userId);

            if (user == null)
            {
                return(NotFound());
            }


            _context.IdentityUser.Remove(user);
            await _context.SaveChangesAsync();

            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();
            }

            var role = _context.IdentityRole.FirstOrDefault(m => m.Name == selectRole);

            if (role == null)
            {
                return(NotFound());
            }

            IdentityUserRole <string> newUserRole = new IdentityUserRole <string>();

            newUserRole.UserId = userId;
            newUserRole.RoleId = role.Id;

            if (ModelState.IsValid)
            {
                _context.Add(newUserRole);
                await _context.SaveChangesAsync();
            }

            return(RedirectToAction("ManageAccounts"));
        }
Example #6
0
        public async Task <IActionResult> BuyPuppy(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            // Code below copied from http://learningprogramming.net/net/asp-net-core-mvc/build-shopping-cart-with-session-in-asp-net-core-mvc/
            // and updated it.

            // Get the puppy from the PricePuppy table
            var pricingPuppyModel = await _context.PricingPuppyModel.FindAsync(id);

            if (pricingPuppyModel == null)
            {
                return(NotFound());
            }

            // Check if the puppy cart has been created or not .i.e is it null
            if (SessionHelper.GetObjectFromJson <List <CartItemModel> >(HttpContext.Session, "puppyCart") == null)
            {
                //Create the cart
                List <CartItemModel> cart = new List <CartItemModel>();

                //Creating cart item model object
                CartItemModel newCartItem = new CartItemModel {
                    PricePuppyID = pricingPuppyModel.PricePuppyID, PricePuppyDesc = pricingPuppyModel.PricePuppyDesc,
                    PricePuppy   = pricingPuppyModel.PricePuppy, TrainingServicesPriceID = -1,
                    TrainingName = "", PriceTraining = 0, CartQty = 1, Email = User.Identity.Name
                };

                cart.Add(newCartItem);

                if (ModelState.IsValid)
                {
                    _context.Add(newCartItem);
                    await _context.SaveChangesAsync();
                }

                SessionHelper.SetObjectAsJson(HttpContext.Session, "puppyCart", cart);
            }
            else
            {
                //The cart has been created
                List <CartItemModel> cart = SessionHelper.GetObjectFromJson <List <CartItemModel> >(HttpContext.Session, "puppyCart");
                int index = isExistPuppy((int)id);

                if (index == -1)
                {
                    CartItemModel newCartItm = new CartItemModel {
                        PricePuppyID = pricingPuppyModel.PricePuppyID, PricePuppyDesc = pricingPuppyModel.PricePuppyDesc,
                        PricePuppy   = pricingPuppyModel.PricePuppy, TrainingServicesPriceID = -1, TrainingName = "", PriceTraining = 0, CartQty = 1,
                        Email        = User.Identity.Name
                    };
                    cart.Add(newCartItm);

                    if (ModelState.IsValid)
                    {
                        _context.Add(newCartItm);
                        await _context.SaveChangesAsync();
                    }
                }

                SessionHelper.SetObjectAsJson(HttpContext.Session, "puppyCart", cart);
            }



            return(RedirectToAction("Index"));
        }