public object SaveAttendance(AttendanceParameterscs atteobj) { SchoolMainContext db = new ConcreateContext().GetContext(atteobj.Userid, atteobj.Password); if (db == null) { return(new Results() { IsSuccess = false, Message = "Invalid User" }); } var AcadamicYear = db.View_GETACADEMICYEAR.FirstOrDefault(); if (AcadamicYear == null) { return(new Results { IsSuccess = false, Message = "Not Found Academic Year" }); } TBLATTENDENCEMASTER objmster = new TBLATTENDENCEMASTER(); TBLATTENDENCE objDetail = new TBLATTENDENCE(); var logindetail = db.TBLUSERLOGINs. Where(r => r.UserId == atteobj.Userid && r.Password == atteobj.Password && r.STATUS == "ACTIVE") .FirstOrDefault(); var ClassTeacherCheck = db.TBLASSIGNCLASSTEACHERs.Where(r => r.DIVISIONID == atteobj.DIVISIONID && r.ACADEMICYEAR == AcadamicYear.ACADEMICYEAR && r.DISPLAY == 1).ToList(); if (ClassTeacherCheck.Count != 0) { var checkatt = db.Vw_ATTENDANCECHECK.FirstOrDefault(r => r.DIVISIONID == atteobj.DIVISIONID && r.ATTEDANCEDATE == atteobj.ATTEDANCEDATE); //Duplicate Attendance Check if (checkatt == null) { try { objmster.ATTEDANCEDATE = atteobj.ATTEDANCEDATE; objmster.DIVISIONID = atteobj.DIVISIONID; objmster.DISPLAY = 1; objmster.EDUCATIONYEAR = AcadamicYear.ACADEMICYEAR; var std = db.vw_FETCHSTANDARDBYDIVISION.Where(r => r.DIVISIONID == atteobj.DIVISIONID && r.DISPLAY == 1 && r.ACADEMICYEAR == AcadamicYear.ACADEMICYEAR).ToList(); objmster.STANDARDID = Convert.ToInt32(std[0].STANDARDID); objmster.CREATEDON = DateTime.Now; objmster.CREATEDID = atteobj.Userid; db.TBLATTENDENCEMASTERs.Add(objmster); db.SaveChanges(); //TBLNOTIFICATION objnotification = new TBLNOTIFICATION(); //objnotification.TITLE = "Daily Attendance"; //objnotification.NOTIFICATIONDATE = DateTime.Now; //objnotification.NOTIFICATIONTIME = DateTime.Now.ToString("h:mm tt"); //objnotification.DIVISIONID = atteobj.DIVISIONID; //objnotification.ACADEMICYEAR = "2018-2019"; //objnotification.NOTIFICATIONTYPE = "Attendance"; //db.TBLNOTIFICATIONs.Add(objnotification); //db.SaveChanges(); string absentno = atteobj.Absentno; if (absentno != "") { string[] sbno = absentno.Split(','); objDetail.ATTEDANCEMID = objmster.ATTEDANCEMID; for (int i = 0; i < sbno.Length; i++) { string abno = sbno[i].ToString(); int rollno = Convert.ToInt32(abno); var getstudent = db.VIEWGETSTUDENTATTs.Where(r => r.DIVISIONID == atteobj.DIVISIONID && r.ROLL_NO == rollno).ToList(); if (getstudent.Count == 0) { return(new Results() { IsSuccess = false, Message = "No students found for this division " }); } objDetail.ATTEDANCEMID = objmster.ATTEDANCEMID; objDetail.ROLLNO = sbno[i].ToString(); objDetail.NAME = getstudent[0].STUDENTNAME; objDetail.STUDENTID = getstudent[0].STUDENTID; objDetail.STATUS = "A"; db.TBLATTENDENCEs.Add(objDetail); db.SaveChanges(); string[] splitname = getstudent[0].STUDENTNAME.Split(' '); TBLNOTIFICATIONDETAIL objnotidetails = new TBLNOTIFICATIONDETAIL(); string str = ""; if (logindetail.UserName.StartsWith("NKV")) { str = "goo.gl/NsoiKY"; } else if (logindetail.UserName.StartsWith("SXS")) { str = "goo.gl/zotf13"; } else if (logindetail.UserName.StartsWith("ASM")) { str = "goo.gl/9vNiX8"; } else if (logindetail.UserName.StartsWith("ASY")) { str = "goo.gl/SNtreT"; } else if (logindetail.UserName.StartsWith("NMS")) { str = "goo.gl/j7XjCx"; } string txtMessage = "Dear Parent, Your Pupil " + splitname[1] + ", is absent on " + Convert.ToDateTime(atteobj.ATTEDANCEDATE).ToString("dd/MM/yyyy") + ", Kindly note. See attendance details " + str; if (smsstatus == "1") { /* uncomment on final launch */ //string responseString = SMSSendTESTDLR(getstudent[0].GMOBILE, txtMessage, logindetail.UserName); //if (responseString != "") //{ // var jObject = JObject.Parse(responseString); // var response = jObject["response"].ToString(); // string RequestId = getRequestID(responseString); // TBLMSGHISTORY smshist = new TBLMSGHISTORY(); // smshist.DATE = DateTime.Now; // smshist.TIME = DateTime.Now.ToShortTimeString(); // smshist.MSG = txtMessage; // smshist.TYPE = "ATT"; // smshist.CREATEDID = atteobj.Userid; // smshist.DISPLAY = 1; // smshist.STUDENTID = getstudent[0].STUDENTID; // smshist.FROMEMPID = Convert.ToInt64(logindetail.EmpCode); // smshist.STATUS = "Out"; // smshist.InStatus = "In"; // smshist.OutStatus = "Out"; // smshist.REQUESTID = RequestId; // smshist.EMPLOYEEID = 0; // smshist.TOEMPID = "0"; // smshist.ATTACHMENTS = ""; // smshist.SUBJECT = ""; // smshist.OtherNos = ""; // smshist.ALUMNIID = 0; // db.TBLMSGHISTORies.Add(smshist); // db.SaveChanges(); //} } //TBLNOTIFICATIONDETAIL objnotidetails = new TBLNOTIFICATIONDETAIL(); FCMPushNotification OBJPUSH = new FCMPushNotification(); //var getsubjectname = db.VIEWSUBJECTNAMEs.Where(r => r.SUBJECTID == obj.subject).ToList(); string studentid = Convert.ToString(getstudent[0].STUDENTID); var userid = db.VIEWGETUSERIDFROMEMPCODEs.Where(r => r.EmpCode == studentid).FirstOrDefault(); var device = db.VW_DEVICE.FirstOrDefault(r => r.UserId == userid.UserId); if (device != null) { if (!string.IsNullOrWhiteSpace(device.DeviceId)) { OBJPUSH.SendNotification("Attendance", string.Format("Dear Parent, Your pupil is absent on dated {0}, kindly note.", objmster.ATTEDANCEDATE.Value.ToString("dd-MM-yyyy")), device.DeviceId); } } } } return(new Results { IsSuccess = true, Message = "Attendance Saved Successfully!" }); } catch (Exception e) { return(new Results { IsSuccess = false, Message = e.Message }); } } return(new Results { IsSuccess = false, Message = "Attedance already taken for this Date" }); } return(new Results { IsSuccess = false, Message = "Class teacher is not assign to this division" }); }
public object SaveAttendance(AttendanceParameterscs atteobj) { SchoolMainContext db = new ConcreateContext().GetContext(atteobj.Userid, atteobj.Password); TBLATTENDENCEMASTER objmster = new TBLATTENDENCEMASTER(); TBLATTENDENCE objDetail = new TBLATTENDENCE(); var checkatt = db.Vw_ATTENDANCECHECK.FirstOrDefault(r => r.DIVISIONID == atteobj.DIVISIONID && r.ATTEDANCEDATE == atteobj.ATTEDANCEDATE); //Duplicate Attendance Check if (checkatt == null) { try { objmster.ATTEDANCEDATE = atteobj.ATTEDANCEDATE; objmster.DIVISIONID = atteobj.DIVISIONID; objmster.DISPLAY = 1; objmster.EDUCATIONYEAR = "2018-2019"; var std = db.vw_FETCHSTANDARDBYDIVISION.Where(r => r.DIVISIONID == atteobj.DIVISIONID && r.DISPLAY == 1 && r.ACADEMICYEAR == "2018-2019").ToList(); objmster.STANDARDID = Convert.ToInt32(std[0].STANDARDID); objmster.CREATEDON = DateTime.Now; objmster.CREATEDID = atteobj.Userid; db.TBLATTENDENCEMASTERs.Add(objmster); db.SaveChanges(); //TBLNOTIFICATION objnotification = new TBLNOTIFICATION(); //objnotification.TITLE = "Daily Attendance"; //objnotification.NOTIFICATIONDATE = DateTime.Now; //objnotification.NOTIFICATIONTIME = DateTime.Now.ToString("h:mm tt"); //objnotification.DIVISIONID = atteobj.DIVISIONID; //objnotification.ACADEMICYEAR = "2018-2019"; //objnotification.NOTIFICATIONTYPE = "Attendance"; //db.TBLNOTIFICATIONs.Add(objnotification); //db.SaveChanges(); string absentno = atteobj.Absentno; string[] sbno = absentno.Split(','); objDetail.ATTEDANCEMID = objmster.ATTEDANCEMID; for (int i = 0; i < sbno.Length; i++) { string abno = sbno[i].ToString(); int rollno = Convert.ToInt32(abno); var getstudent = db.VIEWGETSTUDENTATTs.Where(r => r.DIVISIONID == atteobj.DIVISIONID && r.ROLL_NO == rollno).ToList(); if (getstudent.Count == 0) { return(new Results() { IsSuccess = false, Message = "No students found for this division " }); } objDetail.ATTEDANCEMID = objmster.ATTEDANCEMID; objDetail.ROLLNO = sbno[i].ToString(); objDetail.NAME = getstudent[0].STUDENTNAME; objDetail.STUDENTID = getstudent[0].STUDENTID; objDetail.STATUS = "A"; db.TBLATTENDENCEs.Add(objDetail); db.SaveChanges(); TBLNOTIFICATIONDETAIL objnotidetails = new TBLNOTIFICATIONDETAIL(); // objnotidetails.NOTIFICATIONID = objnotification.NOTIFICATIONID; // objnotidetails.STUDENTID = getstudent[0].STUDENTID; // objnotidetails.STATUS = 0; // db.TBLNOTIFICATIONDETAILs.Add(objnotidetails); // db.SaveChanges(); } return(new Results { IsSuccess = true, Message = "Attendance Save successfully" }); } catch (Exception e) { return(new Error() { IsError = true, Message = e.Message }); } } return(new Results { IsSuccess = false, Message = "Attedance already taken for this Date " }); }
public object SaveAttendance(AttendanceParameterscs atteobj) { SchoolMainContext db = new ConcreateContext().GetContext(atteobj.Userid, atteobj.Password); if (db == null) { return(new Results() { IsSuccess = false, Message = "Invalid User" }); } TBLATTENDENCEMASTER objmster = new TBLATTENDENCEMASTER(); TBLATTENDENCE objDetail = new TBLATTENDENCE(); var checkatt = db.Vw_ATTENDANCECHECK.FirstOrDefault(r => r.DIVISIONID == atteobj.DIVISIONID && r.ATTEDANCEDATE == atteobj.ATTEDANCEDATE); //Duplicate Attendance Check if (checkatt == null) { try { objmster.ATTEDANCEDATE = atteobj.ATTEDANCEDATE; objmster.DIVISIONID = atteobj.DIVISIONID; objmster.DISPLAY = 1; objmster.EDUCATIONYEAR = "2018-2019"; var std = db.vw_FETCHSTANDARDBYDIVISION.Where(r => r.DIVISIONID == atteobj.DIVISIONID && r.DISPLAY == 1 && r.ACADEMICYEAR == "2018-2019").ToList(); objmster.STANDARDID = Convert.ToInt32(std[0].STANDARDID); objmster.CREATEDON = DateTime.Now; objmster.CREATEDID = atteobj.Userid; db.TBLATTENDENCEMASTERs.Add(objmster); db.SaveChanges(); //TBLNOTIFICATION objnotification = new TBLNOTIFICATION(); //objnotification.TITLE = "Daily Attendance"; //objnotification.NOTIFICATIONDATE = DateTime.Now; //objnotification.NOTIFICATIONTIME = DateTime.Now.ToString("h:mm tt"); //objnotification.DIVISIONID = atteobj.DIVISIONID; //objnotification.ACADEMICYEAR = "2018-2019"; //objnotification.NOTIFICATIONTYPE = "Attendance"; //db.TBLNOTIFICATIONs.Add(objnotification); //db.SaveChanges(); string absentno = atteobj.Absentno; string[] sbno = absentno.Split(','); objDetail.ATTEDANCEMID = objmster.ATTEDANCEMID; for (int i = 0; i < sbno.Length; i++) { string abno = sbno[i].ToString(); int rollno = Convert.ToInt32(abno); var getstudent = db.VIEWGETSTUDENTATTs.Where(r => r.DIVISIONID == atteobj.DIVISIONID && r.ROLL_NO == rollno).ToList(); if (getstudent.Count == 0) { return(new Results() { IsSuccess = false, Message = "No students found for this division " }); } objDetail.ATTEDANCEMID = objmster.ATTEDANCEMID; objDetail.ROLLNO = sbno[i].ToString(); objDetail.NAME = getstudent[0].STUDENTNAME; objDetail.STUDENTID = getstudent[0].STUDENTID; objDetail.STATUS = "A"; db.TBLATTENDENCEs.Add(objDetail); db.SaveChanges(); string[] splitname = getstudent[0].STUDENTNAME.Split(' '); TBLNOTIFICATIONDETAIL objnotidetails = new TBLNOTIFICATIONDETAIL(); string txtMessage = "Dear Parent, Your Pupil " + splitname[1] + ", is absent on " + Convert.ToDateTime(atteobj.ATTEDANCEDATE).ToString("dd/MM/yyyy") + ", Kindly note it. See attendance details goo.gl/iTjC9V"; if (smsstatus == "1") { SMSSendTESTDLR(getstudent[0].GMOBILE, txtMessage); } TBLNOTIFICATIONDETAIL objnotidetails = new TBLNOTIFICATIONDETAIL(); FCMPushNotification OBJPUSH = new FCMPushNotification(); //var getsubjectname = db.VIEWSUBJECTNAMEs.Where(r => r.SUBJECTID == obj.subject).ToList(); string studentid = Convert.ToString(getstudent[i].STUDENTID); var userid = db.VIEWGETUSERIDFROMEMPCODEs.Where(r => r.EmpCode == studentid).FirstOrDefault(); var device = db.VW_DEVICE.FirstOrDefault(r => r.UserId == userid.UserId); if (device != null) { if (!string.IsNullOrWhiteSpace(device.DeviceId)) { OBJPUSH.SendNotification("Attendance", string.Format("Dear Parent, Your pupil is absent on dated {0}, kindly note.", objmster.ATTEDANCEDATE.Value.ToString("dd-MM-yyyy")), device.DeviceId); } } } return(new Results { IsSuccess = true, Message = "Attendance Save successfully" }); } catch (Exception e) { return(new Results { IsSuccess = false, Message = e.Message }); } } return(new Results { IsSuccess = false, Message = "Attedance already taken for this Date" }); }