Exemplo n.º 1
0
        public async Task <IActionResult> Create([Bind("BenefitId,UserId,ProjectId")] UsersBenefits usersBenefits)
        {
            var userId = _GetPersonId();

            if (ModelState.IsValid)
            {
                var hasBenefit = await _context.UsersBenefits.AnyAsync(u => u.UserId == _GetPersonId() && u.BenefitId == usersBenefits.BenefitId);

                if (hasBenefit)
                {
                    return(Json(new
                    {
                        status = hasBenefit,
                        message = "You have already bought this package, please select another one!"
                    }));
                }
                else
                {
                    usersBenefits.UserId = _GetPersonId();
                    _context.Add(usersBenefits);
                    await _context.SaveChangesAsync();
                    await _SendMailAsync();

                    return(Json(new
                    {
                        status = hasBenefit,
                        message = "Congratulations! Smart choice to fund this project!"
                    }));
                }
            }
            ViewData["BenefitId"] = new SelectList(_context.Benefit, "BenefitId", "BenefitDesciption", usersBenefits.BenefitId);
            ViewData["UserId"]    = new SelectList(_context.AspNetUsers, "Id", "Id", usersBenefits.UserId);
            return(View(usersBenefits));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("ProjectId,ProjectName,ProjectDescription,AskedFund,Days,NumberOfBenefits,MediaPath,VideoUrl,UserId,StartDate,CategoryId")] Project project, List <Benefit> benefits)
        {
            if (ModelState.IsValid)
            {
                var httpFiles = HttpContext.Request.Form.Files;
                var userId    = _GetPersonId();
                await _projectsCall.ProjectsCreateCall(project, userId, httpFiles);

                foreach (var benefit in benefits)
                {
                    benefit.ProjectId = project.ProjectId;
                }
                _context.Benefit.AddRange(benefits);
                if (project.VideoUrl != null)
                {
                    project.VideoUrl = _EmbeddedVideo(project.VideoUrl);
                }
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            ViewData["CategoryId"] = new SelectList(_context.Category, "CategoryId", "CategoryName", project.CategoryId);
            ViewData["UserId"]     = new SelectList(_context.AspNetUsers, "Id", "Id", project.UserId);
            return(View(project));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("CategoryId,CategoryName")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("BenefitId,BenefitName,BenefitDesciption,ProjectId,BenefitPrice")] Benefit benefit)
        {
            if (ModelState.IsValid)
            {
                _context.Add(benefit);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ProjectId"] = new SelectList(_context.Project, "ProjectId", "ProjectDescription", benefit.ProjectId);
            return(View(benefit));
        }
Exemplo n.º 5
0
 public async Task ProjectsCreateCall(Project project, string userId, IFormFileCollection httpFiles)
 {
     AddMediaFiles(project, userId, httpFiles);
     project.UserId    = userId;
     project.StartDate = DateTime.Today.Date;
     _context.Add(project);
     await _context.SaveChangesAsync();
 }