public async Task FindParticipantAsync_EquivalentToParticipant(Game game, ChallengeState state) { //Arrange var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(48956632, game, state); var challenge = challengeFaker.FakeChallenge(); using var factory = new InMemoryDbContextFactory <ChallengesDbContext>(); await using (var context = factory.CreateContext()) { var challengeRepository = new ChallengeRepository(context); challengeRepository.Create(challenge); await challengeRepository.CommitAsync(); } await using (var context = factory.CreateContext()) { var participantQuery = new ParticipantQuery(context); foreach (var participant in challenge.Participants) { //Act var participantAsync = await participantQuery.FindParticipantAsync(ParticipantId.FromGuid(participant.Id)); //Assert participantAsync.Should().BeEquivalentTo(participant); } } }
public async Task FindChallengeAsync_FromRepository_ShouldNotBeNull() { //Arrange var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(1, Game.LeagueOfLegends); var fakeChallenge = challengeFaker.FakeChallenge(); using var factory = new InMemoryDbContextFactory <ChallengesDbContext>(); await using (var context = factory.CreateContext()) { var repository = new ChallengeRepository(context); repository.Create(fakeChallenge); await repository.CommitAsync(); } await using (var context = factory.CreateContext()) { var repository = new ChallengeRepository(context); //Act var challenge = await repository.FindChallengeOrNullAsync(fakeChallenge.Id); //Assert challenge.Should().NotBeNull(); } }
static void Main() { //IChildRepository childRepo = new ChildRepository(); //IChallengeRepository challengeRepo = new ChallengeRepository(); //childRepo.Save(new Child("Alin", 10)); //childRepo.Save(new Child("Andrei", 12)); //childRepo.Delete(2); /*foreach(var element in childRepo.FindAll()) * { * Trace.WriteLine(element); * }*/ IChildRepository childRepo = new ChildRepository(); IChallengeRepository challengeRepo = new ChallengeRepository(); IEmployeesRepository employeesRepo = new EmployeesRepository(); IEntriesRepository entriesRepo = new EntriesRepository(childRepo, challengeRepo); Service service = new Service(childRepo, challengeRepo, employeesRepo, entriesRepo); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); //Application.Run(new Login(service)); }
/// <inheritdoc/> public Authorization ToAuthorization(IAuthorization data) { var challenges = ChallengeRepository.GetByAuthorization(data.Id); var result = CreateInstance <Authorization>(); return(OnToAuthorizationConvert(result, data, challenges)); }
public JsonResult JoinChallenge(int contentId) { bool result = true; SessionCustom.Begin(); ChaellengeFollowerRepository follower = new ChaellengeFollowerRepository(SessionCustom); follower.Entity.ChallengeId = contentId; follower.Entity.UserId = ((CustomPrincipal)User).UserId; follower.Entity.Date = DateTime.Now; follower.Insert(); follower.Entity = new Domain.Entities.ChaellengeFollower(); follower.Entity.ChallengeId = contentId; int total = follower.GetAll().Count; ChallengeRepository challenge = new ChallengeRepository(SessionCustom); challenge.Entity.ContentId = contentId; challenge.Entity.Followers = total; challenge.Update(); SessionCustom.Commit(); Business.UserRelation.SaveRelationAction(((CustomPrincipal)User).UserId, null, contentId, "follow", this.SessionCustom); return(this.Json(new { result = result })); }
public async Task FetchUserChallengeHistoryAsync_WhenChallengeQuery_ShouldBeChallenge(Game game, ChallengeState state) { //Arrange var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(84566374, game, state); var challenge = challengeFaker.FakeChallenge(); using var factory = new InMemoryDbContextFactory <ChallengesDbContext>(); await using (var context = factory.CreateContext()) { var challengeRepository = new ChallengeRepository(context); challengeRepository.Create(challenge); await challengeRepository.CommitAsync(); } await using (var context = factory.CreateContext()) { var challengeQuery = new ChallengeQuery(context); //Act var challenges = await challengeQuery.FetchUserChallengeHistoryAsync(challenge.Participants.First().UserId, game, state); //Assert challenges.Single().Should().Be(challenge); } }
public async Task FetchChallengesAsync_ShouldHaveCount(Game game, ChallengeState state) { //Arrange var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(84936374, game); var fakeChallenges = challengeFaker.FakeChallenges(4); using var factory = new InMemoryDbContextFactory <ChallengesDbContext>(); await using (var context = factory.CreateContext()) { var challengeRepository = new ChallengeRepository(context); challengeRepository.Create(fakeChallenges); await challengeRepository.CommitAsync(); } await using (var context = factory.CreateContext()) { var challengeQuery = new ChallengeQuery(context); //Act var challenges = await challengeQuery.FetchChallengesAsync(game, state); //Assert challenges.Should().HaveCount(fakeChallenges.Count(challenge => challenge.Game == game && challenge.Timeline == state)); } }
public async Task FindChallengeAsync_ShouldBeChallenge(Game game, ChallengeState state) { //Arrange var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(84568994, game, state); var challenge = challengeFaker.FakeChallenge(); using var factory = new InMemoryDbContextFactory <ChallengesDbContext>(); await using (var context = factory.CreateContext()) { var challengeRepository = new ChallengeRepository(context); challengeRepository.Create(challenge); await challengeRepository.CommitAsync(); } await using (var context = factory.CreateContext()) { var challengeQuery = new ChallengeQuery(context); //Act var challengeAsync = await challengeQuery.FindChallengeAsync(challenge.Id); //Assert challengeAsync.Should().Be(challenge); } }
public async Task FindMatchAsync_ShouldBeEquivalentToMatch(Game game, ChallengeState state) { //Arrange var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(83459632, game, state); var challenge = challengeFaker.FakeChallenge(); using var factory = new InMemoryDbContextFactory <ChallengesDbContext>(); await using (var context = factory.CreateContext()) { var challengeRepository = new ChallengeRepository(context); challengeRepository.Create(challenge); await challengeRepository.CommitAsync(); } await using (var context = factory.CreateContext()) { var matchQuery = new MatchQuery(context); foreach (var match in challenge.Participants.SelectMany(participant => participant.Matches).ToList()) { //Act var matchAsync = await matchQuery.FindMatchAsync(MatchId.FromGuid(match.Id)); //Arrange matchAsync.Should().BeEquivalentTo(match); } } }
public async Task FindParticipantMatchesAsync_ShouldBeEquivalentToParticipantMatchList(Game game, ChallengeState state) { //Arrange var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(89568322, game, state); var challenge = challengeFaker.FakeChallenge(); using var factory = new InMemoryDbContextFactory <ChallengesDbContext>(); await using (var context = factory.CreateContext()) { var challengeRepository = new ChallengeRepository(context); challengeRepository.Create(challenge); await challengeRepository.CommitAsync(); } await using (var context = factory.CreateContext()) { var matchQuery = new MatchQuery(context); foreach (var participant in challenge.Participants) { //Act var matches = await matchQuery.FetchParticipantMatchesAsync(ParticipantId.FromGuid(participant.Id)); //Arrange matches.Should().BeEquivalentTo(participant.Matches.ToList()); } } }
public async Task FindChallengeParticipantsAsync_ShouldBeEquivalentToParticipantList(Game game, ChallengeState state) { //Arrange var challengeFaker = TestData.FakerFactory.CreateChallengeFaker(68545632, game, state); var challenge = challengeFaker.FakeChallenge(); using var factory = new InMemoryDbContextFactory <ChallengesDbContext>(); await using (var context = factory.CreateContext()) { var challengeRepository = new ChallengeRepository(context); challengeRepository.Create(challenge); await challengeRepository.CommitAsync(); } await using (var context = factory.CreateContext()) { var participantQuery = new ParticipantQuery(context); //Act var participants = await participantQuery.FetchChallengeParticipantsAsync(challenge.Id); //Assert participants.Should().BeEquivalentTo(challenge.Participants.ToList()); } }
/// <summary> /// Bind the context and the session with the content /// </summary> /// <param name="context">Context page</param> /// <param name="session">Session object</param> /// <param name="id">Content ID</param> /// <param name="userId">current user ID</param> public void Bind(HttpContextBase context, ISession session, int?id, int?userId, int?LanguageId) { int total = 0; ChallengeRepository challengerepository = new ChallengeRepository(session); this.CollChallenges = challengerepository.ChallengesPaging(1, 6, out total, null, LanguageId); this.TotalCount = total; }
public ChallengesController(ChallengeRepository challengeRepository, UserChallengeRepository userChallengeRepository, FileRepository fileRepository, UserManager <User> userManager, IMapper mapper) { _challengeRepository = challengeRepository; _userChallengeRepository = userChallengeRepository; _fileRepository = fileRepository; _userManager = userManager; _mapper = mapper; }
/// <inheritdoc/> public IChallenge GetById(int id) { var chall = ChallengeRepository.GetById(id); if (chall == null) { throw new MalformedException("Challenge does not exist"); } return(chall); }
/// <inheritdoc/> public void Validate(IChallenge challenge) { if (challenge.Status == ChallengeStatus.Pending) { challenge.Status = ChallengeStatus.Processing; ChallengeRepository.Update(challenge); Logger.Info("Challenge {id} status updated to {status}", challenge.Id, challenge.Status); Task .Run(() => { // validate challenge switch (challenge.Type) { case "http-01": ValidateHttpChallenge(challenge); break; default: throw new Exception($"Unsupported Challenge type '{challenge.Type}'"); } }) .ContinueWith(t => { // Fault validate if (t.IsFaulted) { Error err = t.Exception.InnerException; challenge.Error = ChallengeRepository.CreateError(); challenge.Error.Detail = err.Detail; challenge.Error.Type = err.Type; challenge.Status = ChallengeStatus.Invalid; ChallengeRepository.Update(challenge); } //Complete validate if (t.IsCompleted) { if (challenge.Status == ChallengeStatus.Processing) { challenge.Status = ChallengeStatus.Valid; challenge.Validated = DateTime.UtcNow; ChallengeRepository.Update(challenge); } } Logger.Info("Challenge {id} status updated to {status}", challenge.Id, challenge.Status); }); } else { throw new MalformedException("Wrong challenge status"); } }
/// <inheritdoc/> public IChallenge Create(int authzId, string type) { var challenge = ChallengeRepository.Create(); OnCreateParams(challenge, authzId, type); ChallengeRepository.Add(challenge); Logger.Info("Challenge {id} created", challenge.Id); return(challenge); }
public void AddToMenu() { ChallengeRepository repoInfo = new ChallengeRepository(); Challenge productInfo = new Challenge(4, "Burger N Fries", "Hamburger with potato french fries", "Bread, meat, potato", 5.99m); repoInfo.AddToMenuList(productInfo); List <Challenge> list = repoInfo.GetMenuList(); var expected = 1; var actual = list.Count; Assert.AreEqual(expected, actual); }
public void AddGetUnresolvedTeamChallenges() { //Arrange Data.Entities.HLContext _db = new Data.Entities.HLContext(); ChallengeRepository ChRepo = new ChallengeRepository(_db); TeamRepository TRepo = new TeamRepository(_db); bool add1Success; bool add2Success; List <Challenge> outChas; Team team1 = new Team(); team1.teamname = "Test1"; TRepo.AddTeam(team1); Team Test1 = TRepo.GetByTeamName(team1.teamname); Team team2 = new Team(); team2.teamname = "Test2"; TRepo.AddTeam(team2); Team Test2 = TRepo.GetByTeamName(team2.teamname); Challenge cha1 = new Challenge(Test1, Test2, 1); Challenge cha2 = new Challenge(0, Test1, Test2, 1, true, false); //Act add1Success = ChRepo.AddChallenge(cha1); add2Success = ChRepo.AddChallenge(cha2); outChas = ChRepo.GetUnresolvedTeamChallenges(team1.teamname); foreach (var cha in outChas) { ChRepo.DeleteChallenge(cha); } List <Challenge> tempChas = ChRepo.GetTeamChallenges(team1.teamname); foreach (var cha in tempChas) { ChRepo.DeleteChallenge(cha); } TRepo.DeleteTeam(team1); TRepo.DeleteTeam(team2); //Assert Assert.IsTrue(add1Success); Assert.IsTrue(add2Success); Assert.AreEqual(1, outChas.Count); Assert.AreEqual("Test1", outChas[0].Team1.teamname); }
public IEnumerable <ChallengeDTO> GetChallengesByUser(int userId) { var repo = new ChallengeRepository(); var challengeIds = repo.GetChallengeIdsByUser(userId); var myChallenges = new List <ChallengeDTO>(); foreach (var challengeId in challengeIds) { var challenge = repo.GetChallege(challengeId); myChallenges.Add(challenge); } return(myChallenges); }
public static void Main(string[] args) { IChildRepository childRepo = new ChildRepository(); IChallengeRepository challengeRepo = new ChallengeRepository(); IEmployeesRepository employeesRepo = new EmployeesRepository(); IEntriesRepository entriesRepo = new EntriesRepository(childRepo, challengeRepo); IService service = new Service(childRepo, challengeRepo, employeesRepo, entriesRepo); SerialServer server = new SerialServer("127.0.0.1", 55555, service); server.Start(); Console.WriteLine("Server started ..."); }
public void UpdateChallengeTest() { //Arrange Data.Entities.HLContext _db = new Data.Entities.HLContext(); ChallengeRepository ChRepo = new ChallengeRepository(_db); TeamRepository TRepo = new TeamRepository(_db); bool updateSuccess; Challenge outCha; Team team1 = new Team(); team1.teamname = "Test1"; TRepo.AddTeam(team1); Team Test1 = TRepo.GetByTeamName(team1.teamname); Team team2 = new Team(); team2.teamname = "Test2"; TRepo.AddTeam(team2); Team Test2 = TRepo.GetByTeamName(team2.teamname); Challenge cha1 = new Challenge(Test1, Test2, 1); ChRepo.AddChallenge(cha1); Challenge pullCha = ChRepo.GetTeamChallenges(team1.teamname).FirstOrDefault(); pullCha.MakeReport(pullCha.Team1.teamname, true); pullCha.MakeReport(pullCha.Team2.teamname, false); //Act updateSuccess = ChRepo.UpdateChallenge(pullCha); outCha = ChRepo.GetTeamChallenges(team1.teamname).FirstOrDefault(); List <Challenge> tempChas = ChRepo.GetTeamChallenges(team1.teamname); foreach (var cha in tempChas) { ChRepo.DeleteChallenge(cha); } TRepo.DeleteTeam(team1); TRepo.DeleteTeam(team2); //Assert Assert.IsTrue(updateSuccess); Assert.IsTrue((bool)outCha.Team1Report); Assert.IsFalse((bool)outCha.Team2Report); }
public void RemFromMenuList() { ChallengeRepository repoInfo = new ChallengeRepository(); Challenge productInfo = new Challenge(2, "Burger N Fries", "Hamburger with potato french fries", "Bread, meat, potato", 5.99m); Challenge productInfo2 = new Challenge(3, "Tuna N Chips", "Tuna filet with potato chips", "Bread, tuna, potato", 5.99m); repoInfo.AddToMenuList(productInfo); repoInfo.AddToMenuList(productInfo2); repoInfo.RemFromMenuList(3); List <Challenge> list = repoInfo.GetMenuList(); var expected = 1; var actual = list.Count; Assert.AreEqual(expected, actual); }
/// <summary> /// obtains the challenge detail /// </summary> /// <param name="mod">identifier of module</param> /// <param name="id">identifier of section</param> /// <returns>returns the result to action</returns> public ActionResult Detail(int mod, int id) { ContentManagement objcontentman = new ContentManagement(SessionCustom, HttpContext); ContentRepository objcontent = new ContentRepository(SessionCustom); ChallengeRepository objchallenge = new ChallengeRepository(SessionCustom); FileattachRepository objfiles = new FileattachRepository(SessionCustom); TagRepository objtag = new TagRepository(SessionCustom); SectionRepository objsection = new SectionRepository(SessionCustom); TemplateRepository objtemplate = new TemplateRepository(SessionCustom); TagFacade tagFacade = new TagFacade(); objtemplate.Entity.Type = 0; objchallenge.Entity.ContentId = objfiles.Entity.ContentId = objcontent.Entity.ContentId = id; objchallenge.LoadByKey(); objcontent.LoadByKey(); IEnumerable <Tag> SelectedTags = objtag.GetTagbycontent(id); this.ViewBag.SelectedTags = string.Join("|", SelectedTags.Select(t => t.TagId)); this.ViewBag.NewsTags = string.Empty; return(this.View( "Index", new ChallengeModel() { UserPrincipal = this.CustomUser, ColModul = CustomMemberShipProvider.GetModuls(this.CustomUser.UserId, this.SessionCustom, HttpContext), Module = this.Module, ListFiles = objfiles.GetAllReadOnly(), Challenge = objchallenge.Entity, IContent = objcontent.Entity, Templates = objtemplate.GetAll().Select(t => t.TemplateId), ListContent = objcontent.GetContentRelation(CurrentLanguage.LanguageId.Value), ListTags = SelectedTags, DeepFollower = Business.Utils.GetDeepFollower(objsection.GetAll(), objcontent.Entity.SectionId.Value), CurrentLanguage = this.CurrentLanguage, Categories = objcontent.Categories(), Tags = tagFacade.GetAll().Select(t => new SelectListItem { Text = t.Name, Value = t.TagId.ToString() }) })); }
public void AddGetByTeamNameTest() { //Arrange Data.Entities.HLContext _db = new Data.Entities.HLContext(); ChallengeRepository ChRepo = new ChallengeRepository(_db); TeamRepository TRepo = new TeamRepository(_db); bool addSuccess; Challenge outCha; Team team1 = new Team(); team1.teamname = "Test1"; TRepo.AddTeam(team1); Team Test1 = TRepo.GetByTeamName(team1.teamname); Team team2 = new Team(); team2.teamname = "Test2"; TRepo.AddTeam(team2); Team Test2 = TRepo.GetByTeamName(team2.teamname); Challenge cha = new Challenge(Test1, Test2, 1); //Act addSuccess = ChRepo.AddChallenge(cha); outCha = ChRepo.GetTeamChallenges(team1.teamname).FirstOrDefault(); ChRepo.DeleteChallenge(outCha); TRepo.DeleteTeam(team1); TRepo.DeleteTeam(team2); //Assert Assert.IsTrue(addSuccess); Assert.AreEqual(team1.teamname, outCha.Team1.teamname); Assert.AreEqual(team2.teamname, outCha.Team2.teamname); Assert.AreEqual(1, outCha.GameModeId); }
public void GetChallengeByIdTest() { //Arrange Data.Entities.HLContext _db = new Data.Entities.HLContext(); ChallengeRepository ChRepo = new ChallengeRepository(_db); TeamRepository TRepo = new TeamRepository(_db); Challenge outCha; Challenge badCha; Team team1 = new Team(); team1.teamname = "Test1"; TRepo.AddTeam(team1); Team Test1 = TRepo.GetByTeamName(team1.teamname); Team team2 = new Team(); team2.teamname = "Test2"; TRepo.AddTeam(team2); Team Test2 = TRepo.GetByTeamName(team2.teamname); Challenge cha1 = new Challenge(Test1, Test2, 1); ChRepo.AddChallenge(cha1); int id = (int)ChRepo.GetTeamChallenges(Test1.teamname).FirstOrDefault().id; //Act outCha = ChRepo.GetChallengeById(id); badCha = ChRepo.GetChallengeById(-1); ChRepo.DeleteChallenge(outCha); //Assert Assert.IsNotNull(outCha); Assert.IsNull(badCha); }
public IActionResult AddChallenge(AddChallengeCommand addChallengeCommand) { //create Challenge var repo = new ChallengeRepository(); var startDate = DateTime.Now; var endDate = DateTime.Now.AddMonths(1); var newChallenge = repo.AddChallenge(startDate, endDate, addChallengeCommand.creatorId); var usersToAdd = addChallengeCommand.userIds.Distinct().ToList(); if (!usersToAdd.Contains(addChallengeCommand.creatorId)) { usersToAdd.Add(addChallengeCommand.creatorId); } //add users to Challenge foreach (var userId in usersToAdd) { repo.AddUserToChallenge(newChallenge.Id, userId); } return(Ok()); }
/// <inheritdoc /> public async Task HandleMessage(IPeerSessionMessageContext <AuthenticationServerPayload> context, AuthLogonProofRequest payload) { if (Logger.IsDebugEnabled) { Logger.Debug($"Recieved {payload.GetType().Name} Id: {context.Details.ConnectionId}"); } BigInteger A = payload.A.ToBigInteger(); //SRP6 Safeguard from specification: A % N cannot be 0. if (A % WoWSRP6ServerCryptoServiceProvider.N == 0) { //TODO: This can't be 0 or it breaks } //Check if we have a challenge entry for this connection //TODO: Add proper response code if (!await ChallengeRepository.HasEntry(context.Details.ConnectionId)) { await context.PayloadSendService.SendMessage(new AuthLogonProofResponse(new LogonProofFailure())); return; } //TODO: Refactor using (WoWSRP6PublicComponentHashServiceProvider hasher = new WoWSRP6PublicComponentHashServiceProvider()) { AuthenticationChallengeModel challenge = await ChallengeRepository.Retrieve(context.Details.ConnectionId); byte[] hash = hasher.Hash(A, challenge.PublicB); // Both: u = H(A, B) BigInteger u = hash .Take(20) .ToArray() .ToBigInteger(); BigInteger N = WoWSRP6ServerCryptoServiceProvider.N; //Host: S = (Av^u) ^ b (computes session key) BigInteger S = ((A * (challenge.V.ModPow(u, N)))) //TODO: Do we need % N here? .ModPow(challenge.PrivateB, N); //Host: K = H(S) BigInteger K = hasher.HashSessionKey(S); byte[] preMHash = T3.ToCleanByteArray() .Concat(hasher.Hash(challenge.Identity.Reinterpret(Encoding.ASCII)).Take(20).ToArray()) .Concat(challenge.Salt.ToCleanByteArray()) .Concat(payload.A) .Concat(challenge.PublicB.ToCleanByteArray()) .Concat(K.ToCleanByteArray()) .ToArray(); byte[] M = hasher.Hash(preMHash); Logger.Debug($"M: {M.Aggregate("", (s, b) => $"{s} {b}")}"); Logger.Debug($"M1: {payload.M1.Aggregate("", (s, b) => $"{s} {b}")}"); //TODO: Remove this test code if (TestClass.CompareBuffers(M, payload.M1, 20) == 0) { Logger.Debug($"Auth Proof Success."); byte[] M2 = hasher.Hash(payload.A.Concat(M).Concat(K.ToCleanByteArray()).ToArray()); //TODO: We also want to update last/login IP and other stuff await AccountRepository.UpdateSessionKey(challenge.AccountId, K); await context.PayloadSendService.SendMessage(new AuthLogonProofResponse(new LogonProofSuccess(M2))); } else { Logger.Debug($"Auth Proof Failure."); await context.PayloadSendService.SendMessage(new AuthLogonProofResponse(new LogonProofFailure())); } } //TODO: Implement }
public ChallengeDTO GetChallenge(int challengeId) { var repo = new ChallengeRepository(); return(repo.GetChallege(challengeId)); }
public ActionResult Create(ChallengeModel model, HttpPostedFileBase contentImage, HttpPostedFileBase contentCoverImage, List <string> videoyoutube, string existingTags, string newTags) { ChallengeRepository objchallenge = new ChallengeRepository(this.SessionCustom); ContentManagement objcontent = new ContentManagement(this.SessionCustom, HttpContext); try { DateTime?currentEndDate = null; if (model.IContent.ContentId.HasValue) { objchallenge.Entity.ContentId = model.IContent.ContentId; objchallenge.LoadByKey(); currentEndDate = objchallenge.Entity.EndDate; objchallenge.Entity = new Domain.Entities.Challenge(); } objcontent.ContentImage = contentImage; objcontent.ContentCoverImage = contentCoverImage; objcontent.CollVideos = videoyoutube; this.SessionCustom.Begin(); model.IContent.LanguageId = CurrentLanguage.LanguageId; objcontent.ContentInsert(model.IContent); objchallenge.Entity = model.Challenge; objchallenge.Entity.ExistingTags = !string.Empty.Equals(existingTags) ? existingTags : null; objchallenge.Entity.NewTags = !string.Empty.Equals(newTags) ? newTags : null; if (objchallenge.Entity.ContentId != null) { objchallenge.Update(); bool reactivated = false; if (currentEndDate < DateTime.Now.Date && model.Challenge.EndDate >= DateTime.Now.Date) { reactivated = true; } if (reactivated) { ContentRepository content = new ContentRepository(SessionCustom); content.Entity.ContentId = model.Challenge.ContentId; content.LoadByKey(); Business.Utilities.Notification.StartReActivateProcess(content.Entity.Frienlyname, content.Entity.ContentId.Value, this.HttpContext, this.CurrentLanguage); } this.InsertAudit("Update", this.Module.Name + " -> " + model.IContent.Name); } else { if (!string.IsNullOrEmpty(Request.Form["TempFiles"])) { string[] files = Request.Form["TempFiles"].Split(','); if (files.Length > 0) { if (!Directory.Exists(Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\"))) { Directory.CreateDirectory(Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\")); } } foreach (var item in files) { string filep = Path.Combine(Server.MapPath("~"), @"Files\Images\" + Path.GetFileName(item)); if (System.IO.File.Exists(filep)) { string filedestin = Path.Combine(Server.MapPath("~"), @"Files\Images\" + Path.GetFileName(item)); System.IO.File.Move(filep, Path.Combine(Server.MapPath("~"), @"Files\" + objcontent.ObjContent.ContentId + @"\" + Path.GetFileName(item))); } } } objchallenge.Entity.ContentId = objcontent.ObjContent.ContentId; objchallenge.Entity.Followers = 0; objchallenge.Insert(); ContentRepository content = new ContentRepository(SessionCustom); content.Entity.ContentId = model.Challenge.ContentId; content.LoadByKey(); ////EmailNotificationRepository emailNotification = new EmailNotificationRepository(SessionCustom); ////List<int> users = emailNotification.SendNewProcessNotification(); ////foreach (int userId in users) ////{ //// Business.Utilities.Notification.NewNotification(userId, Domain.Entities.Basic.EmailNotificationType.NEW_PROCESS, null, null, string.Concat("/", content.Entity.Frienlyname), content.Entity.ContentId, content.Entity.ContentId.Value, null, null, null, this.SessionCustom, this.HttpContext, this.CurrentLanguage); ////} Business.Utilities.Notification.StartNewProcess(content.Entity.Frienlyname, content.Entity.ContentId.Value, this.HttpContext, this.CurrentLanguage); this.InsertAudit("Insert", this.Module.Name + " -> " + model.IContent.Name); } this.SessionCustom.Commit(); } catch (Exception ex) { SessionCustom.RollBack(); Utils.InsertLog( this.SessionCustom, "Error" + this.Module.Name, ex.Message + " " + ex.StackTrace); } if (Request.Form["GetOut"] == "0") { return(this.RedirectToAction("Index", "Content", new { mod = Module.ModulId })); } else { return(this.RedirectToAction("Detail", "Challenge", new { mod = Module.ModulId, id = objchallenge.Entity.ContentId })); } }
/// <summary> /// Bind the context and the session with the content /// </summary> /// <param name="context">Context page</param> /// <param name="session">Session object</param> /// <param name="id">Content ID</param> /// <param name="userId">current user ID</param> public void Bind(HttpContextBase context, ISession session, int?id, int?userId, int?LanguageId) { ContentRepository contentrepository = new ContentRepository(session); if (contentrepository.Entity != null) { ChallengeRepository challengepository = new ChallengeRepository(session); FileattachRepository file = new FileattachRepository(session); IdeaRepository idea = new IdeaRepository(session); contentrepository.Entity.ContentId = id; contentrepository.LoadByKey(); if (contentrepository.Entity.Frienlyname != null) { file.Entity.ContentId = challengepository.Entity.ContentId = contentrepository.Entity.ContentId; challengepository.LoadByKey(); this.ObjContent = contentrepository.Entity; this.ObjChallenge = challengepository.Entity; this.CollFiles = file.GetAll(); } contentrepository.Entity = new Content(); contentrepository.Entity.ContentId = this.ObjContent.ContentId; contentrepository.Entity.SectionId = this.ObjContent.SectionId; if (userId.HasValue) { ChaellengeFollowerRepository follower = new ChaellengeFollowerRepository(session); follower.Entity.UserId = userId; follower.Entity.ChallengeId = id; if (follower.GetAll().Count > 0) { this.JoinedChallenge = true; } } if (id.HasValue) { int totalCount = 0; CommentRepository comment = new CommentRepository(session); BlogEntryRepository blog = new BlogEntryRepository(session); idea.Entity.ContentId = blog.Entity.ContentId = id.Value; this.CollIdeas = idea.IdeasPaging(1, 6, out totalCount, id.Value, userId); this.IdeasCount = totalCount; foreach (IdeasPaging item in this.CollIdeas) { item.CollComment = comment.CommentsPaging(1, 3, out totalCount, item.IdeaId.Value); this.CommentsCount = totalCount; } this.BlogEntries = blog.BlogContentEntriesPaging(1, 6, out totalCount); this.BlogEntriesCount = totalCount; foreach (BlogEntriesPaging blogEntry in this.BlogEntries) { blogEntry.CollComment = comment.CommentsPagingContent(1, 3, out totalCount, blogEntry.ContentId.Value); this.CommentsCount = totalCount; } this.TopIdeas = idea.TopIdeas(10); this.Statistics = contentrepository.GetContentStatistics(id.Value); } } this.CollContent = contentrepository.GetNewsRelationFrontEnd(); }