コード例 #1
0
        public IActionResult ProcessTransfer(TransferOwner transfer, int petId, int ownerId)
        {
            int? activeId = HttpContext.Session.GetInt32("activeUser");
            bool isValid  = SecurityCheck.CheckUserCanTransfer(activeId, petId, ownerId, _context);

            if (!isValid)
            {
                //Redirected to Logout as user may be malicious
                return(RedirectToAction("Logout", "PetOwner"));
            }
            var transferPet = _context.pet.SingleOrDefault(p => p.Id == petId);

            if (ModelState.IsValid)
            {
                int newOwnerId = _context.petowner.Single(o => o.Email == transfer.Email).Id;
                transferPet.PetOwnerId = newOwnerId;
                transferPet.Active     = false;
                _context.SaveChanges();
                return(RedirectToAction("Dashboard", "PetOwner"));
            }
            transfer.PetToBeTransferred = (Pet)transferPet;
            transfer.CurrentOwner       = _context.petowner.SingleOrDefault(o => o.Id == (int)activeId);
            transfer.Email = "";
            return(View("Transfer", transfer));
        }
コード例 #2
0
        public IActionResult Transfer(int id)
        {
            int? activeId = HttpContext.Session.GetInt32("activeUser");
            bool isValid  = SecurityCheck.CheckActiveUserVsPet(activeId, id, _context);

            if (isValid == false)
            {
                //Redirected to Logout as user may be malicious
                return(RedirectToAction("Logout", "PetOwner"));
            }
            var           transferPet = _context.pet.SingleOrDefault(p => p.Id == id);
            TransferOwner transfer    = new TransferOwner {
                PetToBeTransferred = (Pet)transferPet,
                CurrentOwner       = _context.petowner.SingleOrDefault(o => o.Id == (int)activeId)
            };

            return(View(transfer));
        }
コード例 #3
0
        public async Task <ActionResult <TransferModel> > transferOwner(TransferOwner murderChildren)
        {
            var profiles = _context.Profiles.Include("User").Where(p => p.User.Email == murderChildren.Email).ToList();

            /* If there are more than one person with the same first and last name,
             * for the scope of this project, we will just say that you cannot transfer
             * ensemble ownership due to the uncertainty of who you are transfering to.
             * Additionally, if there are no matches we will also not allow them to
             * transfer ownership.
             *
             * This is not the ideal solution, but for the scope of our project, this is
             * the solution we are going with.
             *
             * The ideal solution would be to give the user a list of all the matching
             * results and allow them to select which one they would like to transfer to.
             *
             */

            var retModel = new TransferModel();

            if (profiles.Count < 1)
            {
                retModel.Transferred = false;
                retModel.Email       = murderChildren.Email;

                return(retModel);
            }

            var ensemble = _context.Ensembles.Where(e => e.EnsembleId == murderChildren.EnsembleId).First();

            ensemble.UserId = profiles[0].UserId;
            await _context.SaveChangesAsync();

            retModel.Transferred = true;
            retModel.Email       = murderChildren.Email;

            return(retModel);
        }