public JsonResult Create(AddGuarantorViewModel model) { if (ModelState.IsValid) { Guarantor guarantor = new Guarantor(); guarantor.Name = model.Name; guarantor.StudentId = model.StudentId; guarantor.Phone = model.Phone; guarantor.DocUrl = model.DocUrl; var newGuarantor = _employeeRepository.AddGuarantor(guarantor); StudentGuarantor studentGuarantor = new StudentGuarantor { GuarantorId = newGuarantor.ID, StudentId = model.StudentId }; var savedSG = _db.StudentGuarantor.Add(studentGuarantor); _db.SaveChanges(); if (newGuarantor == null) { return(Json(new { success = false, message = "Error while deletiing" })); } else { return(Json(new { success = true, message = "Object saved", type = "guarantor", id = newGuarantor.StudentId })); } } return(Json(new { success = false, message = "Invalid Submission" })); }
public IActionResult AddGuarantor(GuarantorViewModel guarantorModel) { if (ModelState.IsValid) { Guarantor newGuarantor = new Guarantor { Name = guarantorModel.Name, Address = guarantorModel.Address, Number = guarantorModel.Number, Gender = guarantorModel.Gender, Relationship = guarantorModel.Relationship, Occupation = guarantorModel.Occupation, Email = guarantorModel.Email, Nationality = guarantorModel.Nationality }; var model = _guarantorRepository.AddGuarantor(newGuarantor); StudentGuarantor studentGuarantor = new StudentGuarantor { StudentId = guarantorModel.StudentId, GuarantorId = model.Id }; _studentGuarantor.AddStdGtr(studentGuarantor); return(RedirectToAction("studentinfo", "home", new { id = guarantorModel.StudentId })); } return(View(guarantorModel)); }
public StudentGuarantor UpdateStdGtr(StudentGuarantor _studentGuarantor) { var model = dbContext.StudentGuarantors.Attach(_studentGuarantor); model.State = Microsoft.EntityFrameworkCore.EntityState.Modified; dbContext.SaveChanges(); return(_studentGuarantor); }
public StudentGuarantor RemoveStsGtr(Guid Id) { StudentGuarantor studentGuarantor = dbContext.StudentGuarantors.Find(Id); if (studentGuarantor != null) { dbContext.StudentGuarantors.Remove(studentGuarantor); dbContext.SaveChanges(); } return(studentGuarantor); }
public IActionResult AddGuarantor(AddGuarantorViewModel model) { if (ModelState.IsValid) { Guarantor guarantor = new Guarantor(); guarantor.Name = model.Name; guarantor.StudentId = model.StudentId; guarantor.Phone = model.Phone; guarantor.DocUrl = model.DocUrl; var newGuarantor = _employeeRepository.AddGuarantor(guarantor); StudentGuarantor studentGuarantor = new StudentGuarantor { GuarantorId = newGuarantor.ID, StudentId = model.StudentId }; _db.StudentGuarantor.Add(studentGuarantor); _db.SaveChanges(); return(RedirectToAction("Index", "Guarantor")); } return(View(model)); }
public StudentGuarantor AddStdGtr(StudentGuarantor _studentGuarantor) { dbContext.StudentGuarantors.Add(_studentGuarantor); dbContext.SaveChanges(); return(_studentGuarantor); }