Beispiel #1
0
        public async Task <ActionResult> Details(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var user = await UserManager.FindByIdAsync(id);

            ViewBag.RoleNames = await UserManager.GetRolesAsync(user.Id);

            //added to make details full
            RiftWorldEntities db = new RiftWorldEntities();
            var userDeets        = await db.UserDetails.Where(x => x.UserId == id).FirstAsync();

            ViewBag.CurrentCharacter = await db.Characters.Where(x => x.CharacterId == userDeets.CurrentCharacterId).Select(x => x.CharacterName).FirstOrDefaultAsync();

            ViewBag.PastCharacters = db.Characters.Where(x => x.PlayerId == id && x.IsRetired == true).Select(x => x.CharacterName).ToList();
            EditUserViewModel2 daUser = new EditUserViewModel2 {
                Id = user.Id, Email = user.Email, DiscordName = userDeets.DiscordName, DiscordDiscriminator = userDeets.DiscordDiscriminator, IsApproved = userDeets.IsApproved, ConsentFileName = userDeets.ConsentFileName, CurrentCharacterId = userDeets.CurrentCharacterId
            };

            return(View(daUser));
        }
Beispiel #2
0
        public ActionResult Approve([Bind(Include = "Email,Id, ConsentFileName, DiscordName, DiscordDiscriminator, IsApproved")] EditUserViewModel2 editUser, string submit, HttpPostedFileBase consentFile)
        {
            RiftWorldEntities db = new RiftWorldEntities();
            var userDeets        = db.UserDetails.Where(x => x.UserId == editUser.Id).First();

            ViewBag.CurrentCharacter = db.Characters.Where(x => x.CharacterId == userDeets.CurrentCharacterId).Select(x => x.CharacterName).FirstOrDefault();
            ViewBag.PastCharacters   = db.Characters.Where(x => x.PlayerId == editUser.Id && x.IsRetired == true).Select(x => x.CharacterName).ToList();

            if (ModelState.IsValid)
            {
                var user = db.AspNetUsers.Find(editUser.Id);
                if (user == null)
                {
                    return(HttpNotFound());
                }
                if (consentFile != null)
                {
                    string consentName = consentFile.FileName;

                    string   ext      = consentName.Substring(consentName.LastIndexOf('.'));
                    string[] goodExts = { ".pdf" };

                    if (goodExts.Contains(ext.ToLower()))
                    {
                        consentName = editUser.DiscordName + "_" + editUser.DiscordDiscriminator + ext;
                        consentFile.SaveAs(Server.MapPath("~/Content/ConsentFiles/" + consentName));
                        UserDetail userDetail = db.UserDetails.Find(editUser.Id);
                        userDetail.ConsentFileName = consentName;
                        userDetail.IsApproved      = true;
                        db.Entry(userDetail).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    else
                    {
                        ModelState.AddModelError("", "That file type was the incorrect type. It needs to end with either .pdf ");
                        return(View(new EditUserViewModel2()
                        {
                            Id = editUser.Id,
                            Email = editUser.Email,
                            DiscordName = editUser.DiscordName,
                            DiscordDiscriminator = editUser.DiscordDiscriminator,
                            ConsentFileName = editUser.ConsentFileName,
                            IsApproved = editUser.IsApproved
                        }));
                    }
                }
                else if (editUser.ConsentFileName == null)
                {
                    ModelState.AddModelError("", "You need to add the consent form in order to approve a player Katherine. We went over this. You wanted it this way.");
                    return(View(new EditUserViewModel2()
                    {
                        Id = editUser.Id,
                        Email = editUser.Email,
                        DiscordName = editUser.DiscordName,
                        DiscordDiscriminator = editUser.DiscordDiscriminator,
                        ConsentFileName = editUser.ConsentFileName,
                        IsApproved = editUser.IsApproved
                    }));
                }

                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Something failed.");
            return(View(new EditUserViewModel2()
            {
                Id = editUser.Id,
                Email = editUser.Email,
                DiscordName = editUser.DiscordName,
                DiscordDiscriminator = editUser.DiscordDiscriminator,
                ConsentFileName = editUser.ConsentFileName,
                IsApproved = editUser.IsApproved
            }));
        }