public async Task <ActionResult> SelectElectionCource(int?id) { if (id == null) { return(Content(null)); } string resultmsg = id.Value.ToString(); string userName = HttpContext.User.Identity.Name; Term term = _SettingService.GetOptionsForEdit().Term; Student stu = _StudentService.GetByUserId(_UserService.GetUserByUserName(userName).Id); PeresentedCourses pc = _PeresentedCoursesService.GetById(id.Value); ElectionStatus status = _ElectionService.Choosen(stu.Id, pc.Id); switch (status) { case ElectionStatus.Success: { var adv = new Election { Student = _StudentService.GetById(stu.Id), PeresentedCource = pc }; _ElectionService.Insert(adv); _PeresentedCoursesService.Decrease_Capacity_Remained(pc.Id); await _unitOfWork.SaveAllChangesAsync(false); resultmsg = "Success"; } break; case ElectionStatus.CannotSelectCapacityFull: resultmsg = "Cannot Select Beacuse Capacity of Class is Full"; break; case ElectionStatus.CannotSelectOutOfUnit: resultmsg = "Cannot Select Beacuse Out Of Your Max Unit Allowed"; break; case ElectionStatus.CannotSelectPrevSelected: resultmsg = "Cannot Select Beacuse You Pereviouse Choose This Class"; break; } await _unitOfWork.SaveChangesAsync(); CacheManager.InvalidateChildActionsCache(); return(Json(new { msg = resultmsg }, JsonRequestBehavior.AllowGet)); }