Exemple #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,ProjectId,ApplicationUserId,IsApproved,ApprovalRejectionDate,ApprovedRejectedBy,CreatedBy,CreatedOn,UpdatedBy,UpdatedOn")] ProjectStudentChoice projectStudentChoice)
        {
            if (id != projectStudentChoice.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(projectStudentChoice);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProjectStudentChoiceExists(projectStudentChoice.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["ApplicationUserId"] = new SelectList(_context.Users, "Id", "Id", projectStudentChoice.ApplicationUserId);
            ViewData["CreatedBy"]         = new SelectList(_context.Users, "Id", "Id", projectStudentChoice.CreatedBy);
            ViewData["ProjectId"]         = new SelectList(_context.Projects, "Id", "Description", projectStudentChoice.ProjectId);
            ViewData["UpdatedBy"]         = new SelectList(_context.Users, "Id", "Id", projectStudentChoice.UpdatedBy);
            return(View(projectStudentChoice));
        }
Exemple #2
0
        public async Task <IActionResult> Create(int projectId)
        {
            if (ModelState.IsValid)
            {
                var projectStudents = _context.ProjectStudentChoices.Include(p => p.ApplicationUser).Where(p => p.ApplicationUserId == UserIdentity.Id);
                if (projectStudents != null && projectStudents.Count() > 6)
                {
                    return(Json("Error: You have reached maximum attempt = 6"));
                }

                if (projectStudents.FirstOrDefault(p => p.ProjectId == projectId) != null)
                {
                    return(Json("Error: You have have applied on this project previously"));
                }

                var x = await _context.ProjectStudentChoices.Where(p => p.ApplicationUserId == UserIdentity.Id).Select(p => p.Sequence).ToListAsync();

                var i = 0;
                if (x.Count() == 0)
                {
                    i = 1;
                }
                else
                {
                    i = 1 + x.Count();
                    foreach (var k in x)
                    {
                        if (x.Contains(i))
                        {
                            i = i - 1;
                            continue;
                        }
                        break;
                    }
                }

                var CreatedBy            = _context.Projects.Where(p => p.Id == projectId).Select(p => p.CreatedBy).SingleOrDefault();
                var projectStudentChoice = new ProjectStudentChoice
                {
                    ProjectId         = projectId,
                    ApplicationUserId = UserIdentity.Id,
                    CreatedBy         = CreatedBy,
                    CreatedOn         = DateTime.Now,
                    Sequence          = i
                };
                _context.Add(projectStudentChoice);
                await _context.SaveChangesAsync();

                return(Json("Success: Applied successfully"));
                // return Json("Success: Project is Choises successfully."); ;
            }

            return(Json("Invalid"));
        }