public async Task <IActionResult> Create(SemesterViewModel model) { if (ModelState.IsValid) { var semesterExist = _context.Semesters.FirstOrDefault(s => s.Name == model.Name); if (semesterExist != null) { ViewBag.message = "Already Exist"; } var batch = _context.Batches.FirstOrDefault(); if (batch != null) { var s = new Semester { Name = model.Name, Batches = batch }; _context.Semesters.Add(s); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } } return(View(model)); }
public async Task <ActionResult> CreateAsync([Bind("SemesterId,Name,StartDate,EndDate")] SemesterViewModel semester) { if (ModelState.IsValid) { await _semesterService.AddSemesterAsync(semester); return(RedirectToAction(nameof(Index))); } return(View(semester)); }
public SemesterViewModel GetSemesterViewModel(int id) { var semesterInDb = _dbContext.Semesters.SingleOrDefault(s => s.Id == id); var model = new SemesterViewModel() { Semester = semesterInDb }; return(model); }
public SemesterViewModel EditSemester(SemesterViewModel semesterViewModel) { var semesterExist = GetSemesterById(semesterViewModel.Semester.Id); if (semesterExist == null) { var model = new SemesterViewModel() { Semester = semesterViewModel.Semester, StatusMessage = "Error: Semester already exists!" }; return(model); } if (semesterViewModel.Semester.SemesterStartDate < semesterViewModel.Semester.SemesterClosureDate && semesterViewModel.Semester.SemesterClosureDate < semesterViewModel.Semester.SemesterEndDate) { semesterExist.SemesterName = semesterViewModel.Semester.SemesterName; semesterExist.SemesterStartDate = semesterViewModel.Semester.SemesterStartDate; semesterExist.SemesterClosureDate = semesterViewModel.Semester.SemesterClosureDate; semesterExist.SemesterEndDate = semesterViewModel.Semester.SemesterEndDate; semesterExist.UpdateAt = DateTime.Now; _dbContext.SaveChanges(); return(null); } if (semesterViewModel.Semester.SemesterStartDate > semesterViewModel.Semester.SemesterClosureDate) { var model = new SemesterViewModel() { Semester = semesterViewModel.Semester, StatusMessage = "Error: Closure Date must be greater than the Start Date!" }; return(model); } if (semesterViewModel.Semester.SemesterClosureDate > semesterViewModel.Semester.SemesterEndDate) { var model = new SemesterViewModel() { Semester = semesterViewModel.Semester, StatusMessage = "Error: Final Date must be greater than the Closure Date!" }; return(model); } var errorModel = new SemesterViewModel() { Semester = semesterViewModel.Semester, StatusMessage = "Error: There are something wrong then create semester, please check again!" }; return(errorModel); }
public ActionResult Semester(int number = 1) { var semester = (Semester)number; var semesterViewModel = new SemesterViewModel() { Semester = semester, Subjects = _subjectsService.GetBySemester(semester) }; return(View(semesterViewModel)); }
public ActionResult Delete(int id) { tblSemester obj = db.tblSemesters.SingleOrDefault(u => u.SemesterId == id); SemesterViewModel vobj = new SemesterViewModel(); vobj.SemesterName = obj.SemesterName; vobj.Duration = obj.Duration; vobj.Fee = obj.Fee; vobj.StudentId = obj.StudentId; return(View(vobj)); }
// GET: SemesterController/Delete/5 public IActionResult Delete(int id) { var semester = context.Semesters.Find(id); var semesterViewModel = new SemesterViewModel { SemesterName = semester.SemesterName, StartDate = semester.StartDate, EndDate = semester.EndDate, }; return(View(semesterViewModel)); }
public PartialViewResult Details(int id) { tblSemester obj = db.tblSemesters.SingleOrDefault(u => u.SemesterId == id); SemesterViewModel vobj = new SemesterViewModel(); vobj.SemesterName = obj.SemesterName; vobj.Duration = obj.Duration; vobj.Fee = obj.Fee; vobj.StudentId = obj.StudentId; ViewBag.Details = "Show"; return(PartialView("_SemesterDetails", vobj)); }
private bool CheckSemesterValidation(SemesterViewModel semesterViewModel, Semester semesterInDb) { if (semesterInDb == null || (semesterViewModel.Semester.SemesterStartDate < semesterViewModel.Semester.SemesterClosureDate && semesterViewModel.Semester.SemesterClosureDate < semesterViewModel.Semester.SemesterEndDate && semesterInDb.SemesterEndDate < semesterViewModel.Semester.SemesterStartDate)) { return(true); } else { return(false); } }
public async Task <ActionResult> EditAsync(Guid id, [Bind("SemesterId,Name,StartDate,EndDate")] SemesterViewModel semester) { if (id != semester.SemesterId) { return(NotFound()); } if (ModelState.IsValid) { await _semesterService.UpdateSemesterAsync(semester); return(RedirectToAction(nameof(Index))); } return(View(semester)); }
public async Task <ActionResult> Create([Bind(Include = "Description")] SemesterViewModel semesterViewModel) { if (ModelState.IsValid) { Semester semester = new Semester(); semester.Id = Guid.NewGuid(); semester.Description = semesterViewModel.Description; Db.Semesters.Add(semester); await Db.SaveChangesAsync(); Flash.Success("OK", "Semestre Creado Exitosamente"); return(RedirectToAction("Index")); } Flash.Error("Error", "Ha Ocurrido un error al agregar el semestre, revise los campos"); return(View(semesterViewModel)); }
// GET: /Semesters/Edit/5 public async Task <ActionResult> Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SemesterViewModel semester = await Db.Semesters.Select(x => new SemesterViewModel { Id = x.Id, Description = x.Description }).SingleAsync(l => l.Id == id); if (semester == null) { return(HttpNotFound()); } return(View(semester)); }
public async Task <IActionResult> Delete(SemesterViewModel semesterViewModel) { var isSemesterConnectToStudent = context.StudentSemesters .Any(x => x.SemesterId == semesterViewModel.Id); if (!isSemesterConnectToStudent) { var semester = context.Semesters.Find(semesterViewModel.Id); context.Remove(semester); await context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(NotFound("The semester is connected with student(s)")); }
public async Task <ActionResult> Edit([Bind(Include = "Id, Description")] SemesterViewModel semester) { if (ModelState.IsValid) { Semester semesterDomain = new Semester { Id = semester.Id, Description = semester.Description }; Db.Entry(semesterDomain).State = EntityState.Modified; await Db.SaveChangesAsync(); Flash.Success("OK", "Semestre editado exitosamente"); return(RedirectToAction("Index")); } Flash.Error("Error", "El semestre no ha podido ser editado"); return(View(semester)); }
public async Task <SemesterViewModel> UpdateSemesterAsync(SemesterViewModel semester) { try { var jsonPayload = JsonConvert.SerializeObject(semester); var body = new StringContent(jsonPayload, Encoding.UTF8, "application/json"); var response = await Client.PutAsync("api/semester", body); response.EnsureSuccessStatusCode(); } catch (Exception ex) { throw new Exception(ex.Message); } return(semester); }
public ActionResult Edit(SemesterViewModel semesterViewModel) { if (!ModelState.IsValid) { return(View()); } var semester = _semesterRepository.EditSemester(semesterViewModel); if (semester == null) { _logger.LogInformation("Updated semester!"); return(RedirectToAction(nameof(Index))); } ViewData["Message"] = semester.StatusMessage; return(View(semesterViewModel)); }
public IViewComponentResult Invoke() { var allAbsenceTypeValues = (AbsenceType[])Enum.GetValues(typeof(AbsenceType)); ViewBag.Absences = allAbsenceTypeValues; var allApprovalValues = (ApprovalState[])Enum.GetValues(typeof(ApprovalState)); ViewBag.Approvals = allApprovalValues; var semester = new SemesterViewModel { }; semester.users = _context.Users.ToList(); semester.calendar = _context.Calendar.ToList(); return(View(semester)); }
public HttpResponseMessage Post([Bind(Include = "Semester_Name,Model")] SemesterViewModel svm) { //AssignmentManagementSystemEntities db = new AssignmentManagementSystemEntities(); string message = "New Semester Added Successfully"; bool isexists = semDB.CheckSemesterExist(svm.Semester_Name); if (isexists) { ModelState.AddModelError("Semester_Name", "SemesterName Already Exist"); } if (ModelState.IsValid) { semDB.Add(svm); return(Request.CreateResponse(HttpStatusCode.OK, message)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public int Update(SemesterViewModel svm) { tblSemester tb = _db.tblSemesters.Where(s => s.Semester_Id == svm.Id).FirstOrDefault(); var semesterName = tb.Semester_Name; tb.Semester_Name = svm.Semester_Name; _db.SaveChanges(); tblMainLog tml = new tblMainLog(); var principal = System.Security.Claims.ClaimsPrincipal.Current; string Name = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value; str = "Semester Name Updated from '" + semesterName + "' " + "to '" + svm.Semester_Name + "' " + "by Admin"; tml.Description = str; tml.AdminName = Name; tml.Date = System.DateTime.Now; tml.EntityId = 7; tml.ItemId = tb.Semester_Id; _db.tblMainLogs.Add(tml); return(_db.SaveChanges()); }
public int Add(SemesterViewModel svm) { tblSemester tb = new tblSemester(); tb.Semester_Name = svm.Semester_Name; _db.tblSemesters.Add(tb); _db.SaveChanges(); tblMainLog tml = new tblMainLog(); var principal = System.Security.Claims.ClaimsPrincipal.Current; string Name = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value; str = "New Semester '" + svm.Semester_Name + "' " + "Added by Admin"; tml.Description = str; tml.AdminName = Name; tml.Date = System.DateTime.Now; tml.EntityId = 7; tml.ItemId = tb.Semester_Id; _db.tblMainLogs.Add(tml); return(_db.SaveChanges()); }
// /// <summary> /// /// </summary> /// <returns></returns> public ActionResult Index() { ViewBag.SemesterList = Db.Semesters.OrderByDescending(s => s.StartCourses).Select(f => new SelectListItem { Text = f.Name, Value = f.Name, }); var org = GetMyOrganisation(); ViewBag.UserRight = GetUserRight(org); var model = new SemesterViewModel { Semester = SemesterService.GetSemester(DateTime.Today) }; return(View(model)); }
public HttpResponseMessage Put([Bind(Include = "Semester_Name,Model")] SemesterViewModel svm) { AssignmentManagementSystemEntities db = new AssignmentManagementSystemEntities(); var semester = semDB.ListAll().Find(s => s.Id.Equals(svm.Id)); string message = "Semester Updated Successfully"; tblSemester tb = db.tblSemesters.Where(s => s.Semester_Id == svm.Id).FirstOrDefault(); bool isexists = semDB.CheckSemesterExist(svm.Semester_Name); if (isexists) { if (tb.Semester_Name == svm.Semester_Name) { if (ModelState.IsValid) { semDB.Update(svm); return(Request.CreateResponse(HttpStatusCode.OK, message)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } else { ModelState.AddModelError("Semester_Name", "Semester Name Already Exist"); } } if (ModelState.IsValid) { semDB.Update(svm); return(Request.CreateResponse(HttpStatusCode.OK, message)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } }
public SemesterViewModel GetById(int semesterId) { SemesterViewModel result; Semester semester = unitOfWork.Repository <Semester>().GetById(semesterId); if (semester != null) { result = new SemesterViewModel { Id = (int)semester.Id, Name = semester.Name }; } else { result = new SemesterViewModel { Id = 0, Name = "[NoSemester]" }; } return(result); }
public async Task <SemesterViewModel> GetSemesterByIdAsync(Guid semesterId) { var semester = new SemesterViewModel(); try { var response = await Client.GetAsync("api/semester/" + semesterId); if (response.StatusCode == System.Net.HttpStatusCode.OK) { var jsonResponse = await response.Content.ReadAsStringAsync(); var options = new JsonSerializerOptions { PropertyNameCaseInsensitive = true }; semester = System.Text.Json.JsonSerializer.Deserialize <SemesterViewModel>(jsonResponse, options); } } catch (Exception ex) { throw new Exception(ex.Message); } return(semester); }
/// <summary> /// /// </summary> /// <returns></returns> public ActionResult Index() { ViewBag.SemesterList = Db.Semesters.Where(x => x.StartCourses < DateTime.Today).OrderByDescending(s => s.StartCourses).Select(f => new SelectListItem { Text = f.Name, Value = f.Name, }); var user = AppUser; var userRight = GetUserRight(); userRight.IsHost = Db.ActivityDates.Any(d => d.Hosts.Any(h => h.UserId.Equals(user.Id))); ViewBag.UserRight = userRight; var model = new SemesterViewModel { Semester = SemesterService.GetSemester(DateTime.Today) }; return(View(model)); }
public SemesterViewModel CreateSemester(SemesterViewModel semesterViewModel) { if (CheckExistSemester(semesterViewModel.Semester.SemesterName)) { var model = new SemesterViewModel() { Semester = semesterViewModel.Semester, StatusMessage = "Error: Semester already exists!" }; return(model); } var semesterInDb = GetAllSemesters().OrderByDescending(s => s.Id).FirstOrDefault(); var checkValidationSemester = CheckSemesterValidation(semesterViewModel, semesterInDb); if (checkValidationSemester) { var newSemester = new Semester { SemesterName = semesterViewModel.Semester.SemesterName, SemesterStartDate = semesterViewModel.Semester.SemesterStartDate, SemesterClosureDate = semesterViewModel.Semester.SemesterClosureDate, SemesterEndDate = semesterViewModel.Semester.SemesterEndDate }; _dbContext.Semesters.Add(newSemester); _dbContext.SaveChanges(); return(null); } if (semesterViewModel.Semester.SemesterStartDate > semesterViewModel.Semester.SemesterClosureDate) { var model = new SemesterViewModel() { Semester = semesterViewModel.Semester, StatusMessage = "Error: Closure Date must be greater than the Start Date!" }; return(model); } if (semesterViewModel.Semester.SemesterClosureDate > semesterViewModel.Semester.SemesterEndDate) { var model = new SemesterViewModel() { Semester = semesterViewModel.Semester, StatusMessage = "Error: Final Date must be greater than the Closure Date!" }; return(model); } if (semesterInDb.SemesterEndDate > semesterViewModel.Semester.SemesterStartDate) { var model = new SemesterViewModel() { Semester = semesterViewModel.Semester, StatusMessage = "Error: Please check Start Date again!" }; return(model); } var errorModel = new SemesterViewModel() { Semester = semesterViewModel.Semester, StatusMessage = "Error: There are something wrong then create semester, please check again!" }; return(errorModel); }
public Task <Semester> MapViewModelToSemesterDomain(SemesterViewModel semesterViewModel) { throw new NotImplementedException(); }
public static List <IndexCourseViewModel> GetCourses(this SemesterViewModel semester, StudyProgram studyProgram) { return(semester.Courses[studyProgram]); }
public ActionResult Create(SemesterViewModel Smvobj) { var result = false; try { tblSemester obj; if (Smvobj.SemesterId == 0) { obj = new tblSemester(); obj.SemesterName = Smvobj.SemesterName; obj.Duration = Smvobj.Duration; obj.Fee = Smvobj.Fee; obj.StudentId = Smvobj.StudentId; //string fileName = Path.GetFileNameWithoutExtension(vobj.ImageFile.FileName); //string extension = Path.GetExtension(vobj.ImageFile.FileName); //fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; //vobj.ImageUrl = "~/Images/" + fileName; //fileName = Path.Combine(Server.MapPath("~/Images/" + fileName)); //vobj.ImageFile.SaveAs(fileName); //obj.ImageName = vobj.ImageName; //obj.ImageUrl = vobj.ImageUrl; db.tblSemesters.Add(obj); db.SaveChanges(); result = true; } else { obj = db.tblSemesters.SingleOrDefault(u => u.SemesterId == Smvobj.SemesterId); obj.SemesterName = Smvobj.SemesterName; obj.Duration = Smvobj.Duration; obj.Fee = Smvobj.Fee; obj.StudentId = Smvobj.StudentId; //string fileName = Path.GetFileNameWithoutExtension(vobj.ImageFile.FileName); //string extension = Path.GetExtension(vobj.ImageFile.FileName); //fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension; //vobj.ImageUrl = "~/Images/" + fileName; //fileName = Path.Combine(Server.MapPath("~/Images/" + fileName)); //vobj.ImageFile.SaveAs(fileName); //obj.ImageName = vobj.ImageName; //obj.ImageUrl = vobj.ImageUrl; db.SaveChanges(); result = true; } if (result) { return(RedirectToAction("Index")); } else { return(View()); } } catch (Exception ex) { throw; } }