/// <summary> /// Change the weekly pay of a group /// </summary> /// <param name="order">The info to change the weekly pay</param> /// See <see cref="Areas.GroupManage.Models.ManageWeeklyPay"/> to know the param structure /// <returns>The updated group page</returns> /// See <see cref="Areas.GroupManage.Models.GroupPage"/> to know the response structure public IActionResult manageWeeklyPay([FromBody] ManageWeeklyPay order) { User user = TokenUserManager.getUserFromToken(HttpContext, _context); //The user who tries to make admin to another user if (!user.open) { return(BadRequest(new { error = "YoureBanned" })); } if (AdminPolicy.isAdmin(user, _context)) { return(BadRequest("notAllowed")); } Group group = new Group(); if (!GroupMakerFuncionlities.checkFuncionality(user, ref group, order.groupName, GroupMakerFuncionality.MANAGEWEEKPAY, _context, "", "")) { return(BadRequest()); } if (order.weeklyPay < 100 || order.weeklyPay > 2000) { return(BadRequest()); } if (!group.open) { return(BadRequest(new { error = "GroupBanned" })); } try { int oldPay = group.weeklyPay; group.weeklyPay = order.weeklyPay; _context.Update(group); _context.SaveChanges(); launchNews_changeUserCoins(group, oldPay, order.weeklyPay, user.id); _context.SaveChanges(); return(Ok(GroupPageManager.GetPage(user, group, _context))); } catch (Exception) { return(StatusCode(500)); } }
/// <summary> /// Mange the password of the group /// </summary> /// <param name="order">The info to manage the password of the group</param> /// See <see cref="Areas.GroupManage.Models.ManagePassword"/> to know the param structure /// <returns>The updated group page</returns> /// See <see cref="Areas.GroupManage.Models.GroupPage"/> to know the response structure public IActionResult managePassword([FromBody] ManagePassword order) { User user = TokenUserManager.getUserFromToken(HttpContext, _context); //The user who tries to make admin to another user if (!user.open) { return(BadRequest(new { error = "YoureBanned" })); } if (AdminPolicy.isAdmin(user, _context)) { return(BadRequest("notAllowed")); } Group group = new Group(); if (!GroupMakerFuncionlities.checkFuncionality(user, ref group, order.name, GroupMakerFuncionality.MANAGE_PASSWORD, _context, order.newPassword, order.oldPassword)) { return(BadRequest()); } if (group.password != null && !PasswordHasher.areEquals(order.oldPassword, group.password)) { return(BadRequest(new { error = "IncorrectOldPassword" })); } if (!group.open) { return(BadRequest(new { error = "GroupBanned" })); } try { group.password = order.newPassword == null ? null : PasswordHasher.hashPassword(order.newPassword); _context.Update(group); _context.SaveChanges(); Home.Util.GroupNew.launch(null, group, null, Home.Models.TypeGroupNew.MAKE_PRIVATE, group.password != null, _context); return(Ok(GroupPageManager.GetPage(user, group, _context))); } catch (Exception) { return(StatusCode(500)); } }
/// <summary> /// Get the info to launch a new fb /// </summary> /// <param name="groupName">The name of the group where the new bet wants to be launched</param> /// <returns>IActionResult of the get fb page action</returns> /// See <see cref="Areas.GroupManage.Models.LaunchFootballBetManager"/> to know the response structure public IActionResult getFootBallPage([Required] string groupName) { User caller = TokenUserManager.getUserFromToken(HttpContext, _context); if (!caller.open) { return(BadRequest(new { error = "YoureBanned" })); } if (AdminPolicy.isAdmin(caller, _context)) { return(BadRequest("notAllowed")); } Group group = new Group(); if (!GroupMakerFuncionlities.checkFuncionality(caller, ref group, groupName, GroupMakerFuncionality.STARTCREATE_FOOTBALL_BET, _context)) { return(BadRequest()); } if (!checkMaxBetAllowed(group)) { return(Ok(getMaxReachResponse())); } try { List <FootballMatch> availableMatches = getAvailableMatchDays(group); LaunchFootballBetManager response = new LaunchFootballBetManager(); response.typeBets = loadTypeFootballBet(); response.typePays = loadTypePays(); response.competitionMatches = getAvailableBets(availableMatches); return(Ok(response)); } catch (Exception) { return(StatusCode(500)); } }
/// <summary> /// Deletes a group /// </summary> /// <param name="order">The info to remove a group</param> /// See <see cref="Areas.GroupManage.Models.RemoveGroup"/> to know the param structure /// <returns>IActionResult of the remove group action</returns> public IActionResult removeGroup([FromBody] Models.RemoveGroup order) { User user = TokenUserManager.getUserFromToken(HttpContext, _context); //The user who tries to kick the user from the group if (!user.open) { return(BadRequest(new { error = "YoureBanned" })); } if (AdminPolicy.isAdmin(user, _context)) { return(BadRequest("notAllowed")); } Group group = new Group(); if (!GroupMakerFuncionlities.checkFuncionality(user, ref group, order.name, GroupMakerFuncionality.REMOVE_GROUP, _context)) { return(BadRequest()); } if (!PasswordHasher.areEquals(order.userPassword, user.password)) { return(BadRequest(new { error = "IncorrectOldPassword" })); } if (!group.open) { return(BadRequest(new { error = "GroupBanned" })); } try { RemoveGroup.remove(group, _context, _hub); return(Ok(new { success = "SuccesfullGroupRemoved" })); } catch (Exception) { return(StatusCode(500)); } }
/// <summary> /// Launchs a new fb /// </summary> /// <param name="order">The info to launch a new fb</param> /// See <see cref="Areas.Bet.Models.LaunchFootballBet"/> to know the param structure /// <returns>IActionResult of the launch fb action</returns> /// See <see cref="Areas.GroupManage.Models.GroupPage"/> to know the response structure public IActionResult launchBet([FromBody] LaunchFootballBet order) { User caller = TokenUserManager.getUserFromToken(HttpContext, _context); if (!caller.open) { return(BadRequest(new { error = "YoureBanned" })); } if (AdminPolicy.isAdmin(caller, _context)) { return(BadRequest("notAllowed")); } Group group = new Group(); MatchDay match = new MatchDay(); TypeFootballBet typeBet = new TypeFootballBet(); TypePay typePay = new TypePay(); if (!GroupMakerFuncionlities.checkFuncionality(caller, ref group, order.groupName, GroupMakerFuncionality.STARTCREATE_FOOTBALL_BET, _context)) { return(BadRequest()); } if (!getMatchDay(ref match, order.matchday)) { return(BadRequest()); } if (!checkMaxBetAllowed(group)) { return(BadRequest()); } if (!checkParams(ref typeBet, order.typeBet, ref typePay, order.typePay)) { return(BadRequest()); } if (order.lastBetTime > match.date) { return(BadRequest()); } if (!checkMaxMin(order.minBet, order.maxBet)) { return(BadRequest()); } try { FootballBet fb = new FootballBet { MatchDay = match, Group = group, type = typeBet, typePay = typePay, minBet = order.minBet, maxBet = order.maxBet, winRate = typeBet.winRate + typePay.winRate, dateLastBet = order.lastBetTime, dateEnded = match.date }; _context.Add(fb); _context.SaveChanges(); launchNews(caller, group, fb); return(Ok(GroupPageManager.GetPage(caller, group, _context))); } catch (Exception) { return(StatusCode(500)); } }