Example #1
0
        public static void AddGameRoles()
        {
            var db = new EfDbContext();
            var roles = new List<Role>()
            {
                new Role(){Name = "Healer", ImgSrc = string.Empty},
                new Role(){Name = "Tank", ImgSrc = string.Empty},
                new Role(){Name = "DPS", ImgSrc = string.Empty}
            };

            foreach (var role in roles)
            {
                if (!db.Roles.Any(r => r.Name == role.Name))
                {
                    db.Roles.Add(role);
                }
            }

            db.SaveChanges();
        }
Example #2
0
        public JsonResult AddMessage(NewMessageViewModel message)
        {
            if (!string.IsNullOrEmpty(message.MessageBody))
            {
                var context = new EfDbContext();
                var username = User.Identity.IsAuthenticated ? User.Identity.Name : message.Username;

                var newMessage = new Message
                {
                    Username = username,
                    MessageBody = message.MessageBody,
                    PostedDateTime = DateTime.Now,
                    GameId = message.GameId
                };

                var identityManager = new IdentityManager();

                if (User.Identity.IsAuthenticated && !identityManager.IsUserInRole(User.Identity.GetUserId(), "Guest"))
                {
                    if (identityManager.IsUserInRole(User.Identity.GetUserId(), "Member"))
                    {
                        newMessage.Label = "Member";
                    }
                    else if (identityManager.IsUserInRole(User.Identity.GetUserId(), "Admin"))
                    {
                        newMessage.Label = "Admin";
                    }
                }
                else
                {
                    newMessage.Label = "Guest";
                }


                context.Messages.Add(newMessage);
                context.SaveChanges();
                var result = new {message = "Success"};
                return Json(result, JsonRequestBehavior.AllowGet);
            }
            else
            {
                var result = new { message = "Failed" };
                return Json(result, JsonRequestBehavior.AllowGet);
            }
        }