//[ValidateAntiForgeryToken]
        public ActionResult Create(Competition competition, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (competition.StartDate < DateTime.Now)
                {
                    return(Json(new { result = true, mess = "Start time should not be less than current date" }));
                }
                var images = "";
                if (file != null)
                {
                    Task task = Task.Run(async() =>
                    {
                        Account account = new Account("dev2020", "247996535991499", "9jI_5YjJaseBKUrY929sUtt0Fy0");

                        string path           = Path.Combine(Server.MapPath("Images"), Path.GetFileName(file.FileName));
                        Cloudinary cloudinary = new Cloudinary(account);
                        var uploadParams      = new ImageUploadParams()
                        {
                            File = new FileDescription(path, file.InputStream),
                        };
                        var uploadResult = await cloudinary.UploadAsync(uploadParams);
                        images           = uploadResult.SecureUrl.ToString();
                    });
                    task.Wait();
                }
                competition.Logo        = images;
                competition.CreatedTime = DateTime.Now;
                _competitionRepository.Add(competition);
                return(Json(new { result = true, mess = "Create Success", url = "/Admin/Competitions/Index" }));
            }

            return(Json(new { result = false, mess = "Create not Success", url = "/Admin/Competitions/Index" }));
        }
        public void Admin_WhenExistsAtLeastACompetition_ShowListOfExistentCompetitions()
        {
            var competition = new Competition();
            var compRep = new CompetitionRepository {QueryableSession = new InMemoryQueryableSession<Competition>()};
            compRep.Add(competition);

            var controller = new CompetitionController();
            controller.CompetitionRepository = compRep;
            var result = controller.Admin() as ViewResult;

            Assert.IsNotNull(result);
            var model = result.Model as IList<Competition>;
            Assert.IsNotNull(model);
            Assert.IsTrue(model.Contains(competition));
        }
Esempio n. 3
0
        public void DeleteByPOST_WhenExecuteCorrectly_RemoveTheCompetitionFromTheRepository()
        {
            var competition           = new Competition();
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            competitionRepository.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            controller.Delete(competition.Id, new FormCollection());

            Assert.IsFalse(competitionRepository.Contains(competition), "The competition should have been removed from the repository");
        }
Esempio n. 4
0
        public void Delete_LoadTheCompetitionOnTheViewModel()
        {
            var competition           = new Competition();
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            competitionRepository.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Delete(competition.Id);

            var result = actionResult as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual(competition, result.Model);
        }
Esempio n. 5
0
        public void Admin_WhenExistsAtLeastACompetition_ShowListOfExistentCompetitions()
        {
            var competition = new Competition();
            var compRep     = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            compRep.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = compRep;
            var result = controller.Admin() as ViewResult;

            Assert.IsNotNull(result);
            var model = result.Model as IList <Competition>;

            Assert.IsNotNull(model);
            Assert.IsTrue(model.Contains(competition));
        }
Esempio n. 6
0
        public void Details_LoadTheCompetitionOnTheViewModel()
        {
            var competition = new Competition();

            competition.Name = "testingCompetition";
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            competitionRepository.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Details(competition.Name);

            var result = actionResult as ViewResult;

            Assert.AreEqual(competition, result.Model);
        }
Esempio n. 7
0
        public void DeleteByPOST_WhenExecuteCorrectly_RedirectToIndex()
        {
            var competition           = new Competition();
            var competitionRepository = new CompetitionRepository {
                QueryableSession = new InMemoryQueryableSession <Competition>()
            };

            competitionRepository.Add(competition);

            var controller = new CompetitionController();

            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Delete(competition.Id, new FormCollection());

            var redirectToRouteResult = actionResult as RedirectToRouteResult;

            Assert.IsNotNull(redirectToRouteResult);
            Assert.AreEqual("Admin", redirectToRouteResult.RouteValues["action"]);
            Assert.AreEqual("The competition was deleted.", controller.TempData["InformationMessage"]);
        }
Esempio n. 8
0
 public void Add(Competition competition)
 {
     CompetitionRepository.Add(competition);
 }
        public void Details_LoadTheCompetitionOnTheViewModel()
        {
            var competition = new Competition();
            competition.Name = "testingCompetition";
            var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() };
            competitionRepository.Add(competition);

            var controller = new CompetitionController();
            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Details(competition.Name);

            var result = actionResult as ViewResult;
            Assert.AreEqual(competition, result.Model);
        }
        public void Delete_LoadTheCompetitionOnTheViewModel()
        {
            var competition = new Competition();
            var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() };
            competitionRepository.Add(competition);

            var controller = new CompetitionController();
            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Delete(competition.Id);

            var result = actionResult as ViewResult;
            Assert.IsNotNull(result);
            Assert.AreEqual(competition, result.Model);
        }
        public void DeleteByPOST_WhenExecuteCorrectly_RemoveTheCompetitionFromTheRepository()
        {
            var competition = new Competition();
            var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() };
            competitionRepository.Add(competition);

            var controller = new CompetitionController();
            controller.CompetitionRepository = competitionRepository;
            controller.Delete(competition.Id, new FormCollection());

            Assert.IsFalse(competitionRepository.Contains(competition),"The competition should have been removed from the repository");
        }
        public void DeleteByPOST_WhenExecuteCorrectly_RedirectToIndex()
        {
            var competition = new Competition();
            var competitionRepository = new CompetitionRepository { QueryableSession = new InMemoryQueryableSession<Competition>() };
            competitionRepository.Add(competition);

            var controller = new CompetitionController();
            controller.CompetitionRepository = competitionRepository;
            var actionResult = controller.Delete(competition.Id, new FormCollection());

            var redirectToRouteResult = actionResult as RedirectToRouteResult;
            Assert.IsNotNull(redirectToRouteResult);
            Assert.AreEqual("Admin", redirectToRouteResult.RouteValues["action"]);
            Assert.AreEqual("The competition was deleted.", controller.TempData["InformationMessage"]);
        }
Esempio n. 13
0
 public IActionResult Add(Competition competition)
 {
     _competitionRepository.Add(competition);
     return(RedirectToAction("Index"));
 }