public ActionResult Create(Post post, int competition) { var lstImage = new List <string>(); HttpFileCollectionBase files = Request.Files; if (files.Count > 5) { return(Json(new { result = false, mess = "Do not upload larger than 5 images" })); } Task task = Task.Run(async() => { for (int i = 0; i < files.Count; i++) { HttpPostedFileBase file = files[i]; 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); lstImage.Add(uploadResult.SecureUrl.ToString()); } }); task.Wait(); var userID = User.Identity.GetUserId(); post.Id = userID; post.CompetitionId = competition; var commpettion = _competitionRepository.Find(x => x.CompetitionId == post.CompetitionId); if (commpettion == null || commpettion.EndDate < DateTime.Now) { return(Json(new { result = false, mess = "Competition has ended, No new additions allowed" })); } post.Images = string.Join(";", lstImage); post.CreatedTime = DateTime.Now; post.UpdatedTime = DateTime.Now; post.Mark = 0; post.IsPaid = true; post.PriceCustomer = 800; post.IsSold = true; post.Published = true; var result = _postRepository.Add(post); if (result > 0) { return(Json(new { result = true, mess = "Create Success", url = "/Admin/Post/Index" })); } return(Json(new { result = false, mess = "Create not Success", url = "/Admin/Post/Index" })); }
// GET: Admin/Competitions/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Competition competition = _competitionRepository.Find(x => x.CompetitionId == id); if (competition == null) { return(HttpNotFound()); } return(View(competition)); }
/// <summary> /// detail competition /// </summary> /// <param name="competitionId"></param> /// <param name="size"></param> /// <param name="page"></param> /// <param name="searchString"></param> /// <returns></returns> public ActionResult Details(int?competitionId, int?size, int?page, string searchString) { //if (competitionId == null) //{ // return View(); //} var compettion = _competitionRepository.Find(x => x.CompetitionId == competitionId); if (compettion == null) { return(View()); } ViewBag.CompetitionName = compettion.Name; var lstPost = _postRepository.FindAll(x => x.CompetitionId == competitionId).OrderByDescending(x => x.Mark).OrderBy(x => x.UpdatedTime); if (!String.IsNullOrEmpty(searchString)) { ViewBag.CurrentFilter = searchString; lstPost.Where(s => s.User.UserClass.Name.Contains(searchString)); } ViewBag.competitionId = competitionId; ViewBag.stt = 1; ViewBag.currentSize = size; // tạo biến kích thước trang hiện tại ViewBag.total = lstPost.ToList().Count; page = page ?? 1; int pageSize = (size ?? 4); ViewBag.pageSize = pageSize; int pageNumber = (page ?? 1); ViewBag.Page = page; ViewBag.competitionId = competitionId; return(View(lstPost.ToPagedList(pageNumber, pageSize))); }