public int Add(TeacherViewModel tvm) { try { tblTeacher tb = new tblTeacher(); tb.Name = tvm.Name; tb.Email = tvm.Email; tb.Password = CreateRandomPassword(5); tb.Phone = tvm.Phone; tb.Address = tvm.Address; _db.tblTeachers.Add(tb); _db.SaveChanges(); tblMainLog tml = new tblMainLog(); var principal = System.Security.Claims.ClaimsPrincipal.Current; string Name = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value; str = "New Teacher Added With Name- '" + tvm.Name + "' " + ", Email- '" + tvm.Email + "' " + ", Phone- '" + tvm.Phone + "' " + "and Address- '" + tvm.Address + "Added by Admin"; tml.Description = str; tml.AdminName = Name; tml.Date = System.DateTime.Now; tml.EntityId = 4; tml.ItemId = tb.Teacher_Id; _db.tblMainLogs.Add(tml); return(_db.SaveChanges()); } catch (Exception ex) { throw ex; } }
public int Update(SectionViewModel svm) { tblSection tb = _db.tblSections.Where(s => s.Section_Id == svm.Id).FirstOrDefault(); var secName = tb.Sec_Name; tb.Sec_Name = svm.Sec_Name; _db.SaveChanges(); tblMainLog tml = new tblMainLog(); var principal = System.Security.Claims.ClaimsPrincipal.Current; string Name = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value; str = "Section Name Updated from '" + secName + "' " + "to '" + svm.Sec_Name + "' " + "by Admin"; tml.Description = str; tml.AdminName = Name; tml.Date = System.DateTime.Now; tml.EntityId = 8; tml.ItemId = tb.Section_Id; _db.tblMainLogs.Add(tml); return(_db.SaveChanges()); }
public int Add(SectionViewModel svm) { tblSection tb = new tblSection(); tb.Sec_Name = svm.Sec_Name; _db.tblSections.Add(tb); _db.SaveChanges(); tblMainLog tml = new tblMainLog(); var principal = System.Security.Claims.ClaimsPrincipal.Current; string Name = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value; str = "New Section '" + svm.Sec_Name + "' " + "Added by Admin"; tml.Description = str; tml.AdminName = Name; tml.Date = System.DateTime.Now; tml.EntityId = 8; tml.ItemId = tb.Section_Id; _db.tblMainLogs.Add(tml); return(_db.SaveChanges()); }
public int Update(FacultyViewModel fvm) { tblFaculty tb = _db.tblFaculties.Where(f => f.Faculty_Id == fvm.Id).FirstOrDefault(); var facName = tb.Faculty_Name; tb.Faculty_Name = fvm.Faculty_Name; _db.SaveChanges(); tblMainLog tml = new tblMainLog(); var principal = System.Security.Claims.ClaimsPrincipal.Current; string Name = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value; str = "Faculty Name Updated from '" + facName + "' " + "to '" + fvm.Faculty_Name + "' " + "by Admin"; tml.Description = str; tml.AdminName = Name; tml.Date = System.DateTime.Now; tml.EntityId = 6; tml.ItemId = tb.Faculty_Id; _db.tblMainLogs.Add(tml); return(_db.SaveChanges()); }
public int Add(FacultyViewModel fvm) { tblFaculty tb = new tblFaculty(); tb.Faculty_Name = fvm.Faculty_Name; _db.tblFaculties.Add(tb); _db.SaveChanges(); tblMainLog tml = new tblMainLog(); var principal = System.Security.Claims.ClaimsPrincipal.Current; string Name = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value; str = "New Faculty '" + fvm.Faculty_Name + "' " + "Added by Admin"; tml.Description = str; tml.AdminName = Name; tml.Date = System.DateTime.Now; tml.EntityId = 6; tml.ItemId = tb.Faculty_Id; _db.tblMainLogs.Add(tml); return(_db.SaveChanges()); }
public int Update(YearBatchViewModel yvm) { tblYearBatch tb = _db.tblYearBatches.Where(y => y.YearBatchId == yvm.Id).FirstOrDefault(); var yearName = tb.Year_Batch; tb.Year_Batch = yvm.Year_Batch; _db.SaveChanges(); tblMainLog tml = new tblMainLog(); var principal = System.Security.Claims.ClaimsPrincipal.Current; string Name = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value; str = "YearBatch Updated from '" + yearName + "' " + "to '" + yvm.Year_Batch + "' " + "by Admin"; tml.Description = str; tml.AdminName = Name; tml.Date = System.DateTime.Now; tml.EntityId = 5; tml.ItemId = tb.YearBatchId; _db.tblMainLogs.Add(tml); return(_db.SaveChanges()); }
public int Add(YearBatchViewModel yvm) { tblYearBatch tb = new tblYearBatch(); tb.Year_Batch = yvm.Year_Batch; _db.tblYearBatches.Add(tb); _db.SaveChanges(); tblMainLog tml = new tblMainLog(); var principal = System.Security.Claims.ClaimsPrincipal.Current; string Name = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value; str = "New Yearbatch '" + yvm.Year_Batch + "' " + "Added by Admin"; tml.Description = str; tml.AdminName = Name; tml.Date = System.DateTime.Now; tml.EntityId = 5; tml.ItemId = tb.YearBatchId; _db.tblMainLogs.Add(tml); return(_db.SaveChanges()); }
public int Update(TeacherViewModel tvm) { try { tblTeacher tb = _db.tblTeachers.Where(t => t.Teacher_Id == tvm.Id).FirstOrDefault(); //var oldName = tb.Name; //var oldEmail = tb.Email; //var oldPhone = tb.Phone; //var oldAddress = tb.Address; List <string> lstchange = new List <string>(); if (tb.Name != tvm.Name) { lstchange.Add("name from " + tb.Name + " to " + tvm.Name); } if (tb.Email != tvm.Email) { lstchange.Add("email from " + tb.Email + " to " + tvm.Email); } if (tb.Phone != tvm.Phone) { lstchange.Add("phone from " + tb.Phone + " to " + tvm.Phone); } if (tb.Address != tvm.Address) { lstchange.Add("address from " + tb.Address + " to " + tvm.Address); } tb.Name = tvm.Name; tb.Email = tvm.Email; tb.Password = tb.Password; tb.Phone = tvm.Phone; tb.Address = tvm.Address; //_db.SaveChanges(); if (lstchange.Count == 0) { return(_db.SaveChanges()); } else { tblMainLog tml = new tblMainLog(); var principal = System.Security.Claims.ClaimsPrincipal.Current; string Name = principal.FindFirst(ClaimsIdentity.DefaultNameClaimType).Value; foreach (var item in lstchange) { str += item + ","; } string str2 = str; tml.Description = str; tml.AdminName = Name; tml.Date = System.DateTime.Now; tml.EntityId = 4; tml.ItemId = tb.Teacher_Id; _db.tblMainLogs.Add(tml); return(_db.SaveChanges()); } } catch (Exception ex) { throw ex; } }