Ejemplo 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));
        }
Ejemplo n.º 2
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();
 }
Ejemplo 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));
        }
Ejemplo 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));
        }