public JsonResult InsertStudent(IndexStudentsListVM obj) { var result = (dynamic)null; string message = (dynamic)null; try { if (obj.Students != null) { var Students = new InsertStudent_Students() { ClassId = obj.Students.ClassId, GenderId = obj.Students.GenderId, RegistrationNo = obj.Students.RegistrationNo, FirstName = obj.Students.FirstName, LastName = obj.Students.LastName, FatherName = obj.Students.FatherName, MotherName = obj.Students.MotherName, IP300X200 = obj.Students.IP300X200, Year = obj.Students.Year, PresentAddress = obj.Students.PresentAddress, PermanentAddress = obj.Students.PermanentAddress, DOB = obj.Students.DOB, fleImage = obj.Students.fleImage, IsActive = obj.Students.IsActive, AddedBy = 0, AddedDate = DateTime.Now, ModifiedBy = 0, ModifiedDate = DateTime.Now, DataType = null }; var StudentPromotions = new InsertStudent_StudentPromotions() { ClassId = obj.Students.ClassId, StudentId = obj.Students.Id, Year = obj.Students.Year, RollNo = obj.StudentPromotions.RollNo, IsActive = obj.Students.IsActive, AddedBy = 0, AddedDate = DateTime.Now, ModifiedBy = 0, ModifiedDate = DateTime.Now, DataType = null }; var model = new InsertStudent() { WebRootPath = _he.WebRootPath, Students = Students, StudentPromotions = StudentPromotions }; message = _studentsServ.InsertStudent(model); result = Json(new { success = true, Message = message }); } } // catch (Exception) catch (Exception ex) { result = Json(new { success = false, Message = "ERROR101:Students/InsertStudent - " + ex.Message }); } return(result); }
public string InsertStudent(InsertStudent obj) { string returnResult = (dynamic)null; try { var studentsList = _studentsRepo.GetAll().ToList(); var getregistration = (from stu in studentsList where stu.RegistrationNo == obj.Students.RegistrationNo select stu).SingleOrDefault(); //var Studentlist = _studentsRepo.Get(obj.Students.Id); //var query=(from stu) if (getregistration == null) { if (obj != null) { var AdmittedYear = DateTime.ParseExact(obj.Students.Year, "yyyy", null); //[Note: insert 'states' table] if (obj.Students != null) { var Students = new InsertStudent_Students() { ClassId = obj.Students.ClassId, GenderId = obj.Students.GenderId, RegistrationNo = obj.Students.RegistrationNo, FirstName = obj.Students.FirstName, LastName = obj.Students.LastName, IP300X200 = obj.Students.IP300X200, AdmittedYear = AdmittedYear, PresentAddress = obj.Students.PresentAddress, PermanentAddress = obj.Students.PermanentAddress, DOB = obj.Students.DOB, IsActive = obj.Students.IsActive, AddedBy = obj.Students.AddedBy = 0, AddedDate = DateTime.Now, ModifiedBy = 0, ModifiedDate = DateTime.Now, FatherName = obj.Students.FatherName, MotherName = obj.Students.MotherName, DataType = null }; //[NOTE: Student table] _studentsRepo.Insert(Students); if (obj.Students.fleImage != null) { string imagePathIP300X200 = "ClientDictionary/Students/IP300X200/"; string extension = Path.GetExtension(obj.Students.fleImage.FileName); var lastAddingRecord = _studentsRepo.GetAll().Last(); if (_commonServ.CommImage_ImageFormat(lastAddingRecord.Id.ToString(), obj.Students.fleImage, obj.WebRootPath, imagePathIP300X200, 200, 300, extension).Equals(true)) { //[NOTE:Update image file] var imgStudent = _studentsRepo.Get(lastAddingRecord.Id); imgStudent.IP300X200 = imagePathIP300X200 + lastAddingRecord.Id + extension; _studentsRepo.Update(imgStudent); } } } Int64 getLastId = _studentsRepo.GetLastId(); //[NOTE: Student promotion table table] if (obj.StudentPromotions != null) { var StudentPromotions = new InsertStudent_StudentPromotions() { StudentId = getLastId, ClassId = obj.Students.ClassId, RollNo = obj.StudentPromotions.RollNo, ClassYear = AdmittedYear, IsActive = obj.Students.IsActive, AddedBy = 0, AddedDate = DateTime.Now, ModifiedBy = 0, ModifiedDate = DateTime.Now, DataType = null }; _StudentPromotionsRepo.Insert(StudentPromotions); } } returnResult = "Saved"; } else { returnResult = "this registration number already exist"; } } catch (Exception ex) { returnResult = "ERROR102:Insert all required Info - " + ex.Message; } return(returnResult); }