Ejemplo n.º 1
0
        public object Savehomework(homeworkparameters obj)
        {
            SchoolMainContext db          = new ConcreateContext().GetContext(obj.Userid, obj.Password);
            TBLHOMEWORK       objHomework = new TBLHOMEWORK();

            //  objHomework.STANDARDID = obj.standard;

            objHomework.DIVISIONID   = obj.division;
            objHomework.SUBJECTID    = obj.subject;
            objHomework.TERMID       = obj.term;
            objHomework.HOMEWORK     = obj.homeworkdescription;
            objHomework.HOMEWORKDATE = DateTime.Now;
            objHomework.DISPLAY      = 1;
            objHomework.ACADEMICYEAR = "2018-2019";

            db.TBLHOMEWORKs.Add(objHomework);
            db.SaveChanges();

            TBLNOTIFICATION objnotification = new TBLNOTIFICATION();

            objnotification.TITLE            = obj.homeworkdescription;
            objnotification.NOTIFICATIONDATE = DateTime.Now;
            objnotification.NOTIFICATIONTIME = DateTime.Now.ToString("h:mm tt");
            objnotification.DIVISIONID       = int.Parse(obj.division);
            objnotification.ACADEMICYEAR     = "2018-2019";
            objnotification.NOTIFICATIONTYPE = "Homework";
            db.TBLNOTIFICATIONs.Add(objnotification);
            db.SaveChanges();


            string[] divid = objHomework.DIVISIONID.ToString().Split(',');
            for (int d = 0; d < divid.Length; d++)
            {
                int singledivision = Convert.ToInt32(divid[d]);
                var getstudent     = db.VIEWGETSTUDENTATTs.Where(r => r.DIVISIONID == singledivision).ToList();

                if (getstudent == null)
                {
                    return(new Error());
                }
                // return getstudent;
                for (int i = 0; i < getstudent.Count; i++)
                {
                    TBLNOTIFICATIONDETAIL objnotidetails = new TBLNOTIFICATIONDETAIL();
                    objnotidetails.NOTIFICATIONID = objnotification.NOTIFICATIONID;
                    objnotidetails.STUDENTID      = getstudent[i].STUDENTID;
                    objnotidetails.STATUS         = 0;
                    db.TBLNOTIFICATIONDETAILs.Add(objnotidetails);
                    db.SaveChanges();
                    SMSSend(objHomework.HOMEWORK, getstudent[i].GMOBILE);
                }
            }
            return("sms send successfully");
        }
Ejemplo n.º 2
0
        public object HomeworkSave([FromBody] homeworkparameters hobj)
        {
            Homeworkbussinesslayer bhobj = new Homeworkbussinesslayer();


            var result = bhobj.Savehomework(hobj);

            //  bhobj.StudentsMethod(hobj);

            return(result);
        }
Ejemplo n.º 3
0
        public object HomeworkSave([FromBody] homeworkparameters hobj)
        {
            Homeworkbussinesslayer bhobj = new Homeworkbussinesslayer();


            bhobj.Savehomework(hobj);
            //  bhobj.StudentsMethod(hobj);


            return(new Results
            {
                IsSuccess = true,
                Message = "Homework assign successfully"
            });
        }
Ejemplo n.º 4
0
 public object TestNotification(homeworkparameters obj)
 {
     try
     {
         Homeworkbussinesslayer objp = new Homeworkbussinesslayer();
         var homemworkresult         = objp.SendNotificaiton(obj);
         return(homemworkresult);
     }
     catch (Exception e)
     {
         return(new Error()
         {
             IsError = true, Message = e.Message
         });
     }
 }
Ejemplo n.º 5
0
        public object HomeworkSave()
        {
            homeworkparameters obj = new homeworkparameters();

            try
            {
                Homeworkbussinesslayer objp = new Homeworkbussinesslayer();
                var homemworkresult         = objp.FileUpload(obj);
                return(homemworkresult);
            }
            catch (Exception e)
            {
                return(new Error()
                {
                    IsError = true, Message = e.Message
                });
            }
        }
Ejemplo n.º 6
0
        public object SendNotificaiton(homeworkparameters obj)
        {
            SchoolMainContext db = new ConcreateContext().GetContext(obj.Userid, obj.Password);

            if (db == null)
            {
                return(new Results()
                {
                    IsSuccess = false, Message = "Invalid User"
                });
            }
            var device = db.VW_DEVICE.FirstOrDefault(r => r.UserId == obj.Userid);

            if (device != null)
            {
                FCMPushNotification OBJPUSH = new FCMPushNotification();
                return(OBJPUSH.SendNotification("Homework", obj.homeworkdescription, device.DeviceId));
            }

            throw new Exception("Notification Failed");
        }
        public object Savehomework(homeworkparameters obj)
        {
            SchoolMainContext db          = new ConcreateContext().GetContext(obj.Userid, obj.Password);
            TBLHOMEWORK       objHomework = new TBLHOMEWORK();
            var getUserType = db.VW_GET_USER_TYPE.Where(r => r.UserId == obj.Userid).FirstOrDefault();



            objHomework.STANDARDID = int.Parse(obj.standardid);


            objHomework.CREATEDID    = int.Parse(getUserType.EmpCode);
            objHomework.DIVISIONID   = obj.division.ToString();
            objHomework.SUBJECTID    = obj.subject;
            objHomework.TERMID       = obj.term;
            objHomework.HOMEWORK     = obj.homeworkdescription;
            objHomework.HOMEWORKDATE = Convert.ToDateTime(DateTime.Now.ToShortDateString());
            objHomework.TIME         = DateTime.Now.ToShortTimeString();
            objHomework.DISPLAY      = 1;
            objHomework.ACADEMICYEAR = "2018-2019";

            db.TBLHOMEWORKs.Add(objHomework);
            db.SaveChanges();

            TBLNOTIFICATION objnotification = new TBLNOTIFICATION();

            objnotification.TITLE            = obj.homeworkdescription;
            objnotification.NOTIFICATIONDATE = DateTime.Now;
            objnotification.NOTIFICATIONTIME = DateTime.Now.ToString("h:mm tt");
            objnotification.DIVISIONID       = int.Parse(obj.division);
            objnotification.ACADEMICYEAR     = "2018-2019";
            objnotification.NOTIFICATIONTYPE = "Homework";
            db.TBLNOTIFICATIONs.Add(objnotification);
            db.SaveChanges();


            string[] divid = objHomework.DIVISIONID.ToString().Split(',');
            for (int d = 0; d < divid.Length; d++)
            {
                int singledivision = Convert.ToInt32(divid[d]);
                var getstudent     = db.VIEWGETSTUDENTATTs.Where(r => r.DIVISIONID == singledivision).ToList();

                if (getstudent == null)
                {
                    return(new Error());
                }
                // return getstudent;
                for (int i = 0; i < getstudent.Count; i++)
                {
                    TBLNOTIFICATIONDETAIL objnotidetails = new TBLNOTIFICATIONDETAIL();
                    objnotidetails.NOTIFICATIONID = objnotification.NOTIFICATIONID;
                    objnotidetails.STUDENTID      = getstudent[i].STUDENTID;
                    objnotidetails.STATUS         = 0;
                    db.TBLNOTIFICATIONDETAILs.Add(objnotidetails);
                    db.SaveChanges();
                    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)
                    {
                        OBJPUSH.SendNotification("Homework", obj.homeworkdescription, device.DeviceId);
                    }

                    SMSSend(objHomework.HOMEWORK, getstudent[i].GMOBILE);
                }
            }
            return(new Results
            {
                IsSuccess = true,
                Message = "Homework assign successfully and SMS sent Sucessfully"
            });
        }
Ejemplo n.º 8
0
        public object FileUpload(homeworkparameters obj)
        {
            int Userid           = Convert.ToInt32(HttpContext.Current.Request["Userid"]);
            var Password         = HttpContext.Current.Request["Password"];
            SchoolMainContext db = new ConcreateContext().GetContext(Userid, Password);
            var getUserType      = db.VW_GET_USER_TYPE.Where(r => r.UserId == Userid).FirstOrDefault();

            //if (!Request.Content.IsMimeMultipartContent())
            //{
            //    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            //}
            try
            {
                var httpRequest = HttpContext.Current.Request;
                if (httpRequest.Files.Count > 0)
                {
                    string UploadBaseUrl = ConfigurationManager.AppSettings["UploadBaseURL"];
                    string fileName      = string.Empty;
                    var    filePath      = string.Empty;
                    string savePath      = string.Empty;
                    foreach (string file in httpRequest.Files)
                    {
                        var postedFile = httpRequest.Files[file];
                        fileName = postedFile.FileName;
                        filePath = ConfigurationManager.AppSettings["UploadDir"] + Guid.NewGuid() + fileName;
                        savePath = HttpContext.Current.Server.MapPath(filePath); postedFile.SaveAs(savePath); // NOTE: To store in memory use postedFile.InputStream }
                        TBLHOMEWORK upload = new TBLHOMEWORK();
                        //upload.file_id = Guid.NewGuid().ToString();
                        //upload.name = fileName;

                        upload.STANDARDID   = Convert.ToInt32(HttpContext.Current.Request["standardid"]);
                        upload.CREATEDID    = int.Parse(getUserType.EmpCode);
                        upload.DIVISIONID   = HttpContext.Current.Request["division"];
                        upload.SUBJECTID    = Convert.ToInt32(HttpContext.Current.Request["subject"]);
                        upload.TERMID       = Convert.ToInt32(HttpContext.Current.Request["term"]);
                        upload.HOMEWORK     = HttpContext.Current.Request["homeworkdescription"];
                        upload.HOMEWORKDATE = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                        upload.TIME         = DateTime.Now.ToShortTimeString();
                        upload.DISPLAY      = 1;
                        upload.ACADEMICYEAR = "2018-2019";

                        upload.FILEPATH = UploadBaseUrl + filePath.Replace("~/", "");

                        //upload.insert_date = DateTime.Now;
                        db.TBLHOMEWORKs.Add(upload);
                        db.SaveChanges();

                        return(upload);
                    }

                    return(new Results
                    {
                        IsSuccess = false,
                        Message = new InvalidUser()
                        {
                            IsSuccess = false, Result = "Failed to upload File"
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                return(new Results
                {
                    IsSuccess = false,
                    Message = ex.ToString()
                });
            }


            return(null);
        }
Ejemplo n.º 9
0
        public object FileUpload(homeworkparameters obj)
        {
            int Userid           = Convert.ToInt32(HttpContext.Current.Request["Userid"]);
            var Password         = HttpContext.Current.Request["Password"];
            SchoolMainContext db = new ConcreateContext().GetContext(Userid, Password);

            if (db == null)
            {
                return(new Results()
                {
                    IsSuccess = false, Message = "Invalid User"
                });
            }
            var logindetail = db.TBLUSERLOGINs.
                              Where(r => r.UserId == Userid && r.Password == Password && r.STATUS == "ACTIVE")
                              .FirstOrDefault();
            var getUserType = db.VW_GET_USER_TYPE.Where(r => r.UserId == Userid).FirstOrDefault();

            //if (!Request.Content.IsMimeMultipartContent())
            //{
            //    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            //}
            try
            {
                string UploadBaseUrl = "";
                var    httpRequest   = HttpContext.Current.Request;
                var    AcadamicYear  = db.View_GETACADEMICYEAR.FirstOrDefault();
                if (AcadamicYear == null)
                {
                    return(new Results
                    {
                        IsSuccess = false,
                        Message = "Not Found Academic Year"
                    });
                }
                if (httpRequest.Files.Count > 0)
                {
                    if (logindetail.UserName.StartsWith("NKV"))
                    {
                        UploadBaseUrl = ConfigurationManager.AppSettings["NkvsBaseUrl"];
                    }
                    else if (logindetail.UserName.StartsWith("SXS"))
                    {
                        UploadBaseUrl = ConfigurationManager.AppSettings["StxavierBaseUrl"];
                    }
                    else if (logindetail.UserName.StartsWith("ASM"))
                    {
                        UploadBaseUrl = ConfigurationManager.AppSettings["AsmBaseUrl"];
                    }

                    else if (logindetail.UserName.StartsWith("ASY"))
                    {
                        UploadBaseUrl = ConfigurationManager.AppSettings["AsyBaseUrl"];
                    }
                    else if (logindetail.UserName.StartsWith("NMS"))
                    {
                        UploadBaseUrl = ConfigurationManager.AppSettings["NmsBaseUrl"];
                    }
                    string fileName = string.Empty;
                    var    filePath = string.Empty;
                    string savePath = string.Empty;
                    foreach (string file in httpRequest.Files)
                    {
                        var postedFile = httpRequest.Files[file];
                        fileName = postedFile.FileName;
                        filePath = ConfigurationManager.AppSettings["UploadDir"] + Guid.NewGuid() + fileName;
                        savePath = HttpContext.Current.Server.MapPath(filePath); //postedFile.SaveAs(savePath); // NOTE: To store in memory use postedFile.InputStream }
                        TBLHOMEWORK upload = new TBLHOMEWORK();
                        //upload.file_id = Guid.NewGuid().ToString();
                        //upload.name = fileName;

                        upload.STANDARDID   = Convert.ToInt32(HttpContext.Current.Request["standardid"]);
                        upload.CREATEDID    = int.Parse(getUserType.EmpCode);
                        upload.DIVISIONID   = HttpContext.Current.Request["division"];
                        upload.SUBJECTID    = Convert.ToInt32(HttpContext.Current.Request["subject"]);
                        upload.TERMID       = Convert.ToInt32(HttpContext.Current.Request["term"]);
                        upload.HOMEWORK     = HttpContext.Current.Request["homeworkdescription"];
                        upload.HOMEWORKDATE = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                        upload.TIME         = DateTime.Now.ToShortTimeString();
                        upload.DISPLAY      = 1;
                        upload.ACADEMICYEAR = AcadamicYear.ACADEMICYEAR;

                        upload.FILEPATH = UploadBaseUrl + filePath.Replace("~/", "");

                        //upload.insert_date = DateTime.Now;
                        db.TBLHOMEWORKs.Add(upload);
                        db.SaveChanges();

                        return(new Results
                        {
                            IsSuccess = true,
                            Message = "HomeWork Save Successfully"
                        });
                    }

                    return(new Results
                    {
                        IsSuccess = false,
                        Message = "Failed to upload File"
                    });
                }
                else
                {
                    TBLHOMEWORK upload = new TBLHOMEWORK();
                    //upload.file_id = Guid.NewGuid().ToString();
                    //upload.name = fileName;

                    upload.STANDARDID   = Convert.ToInt32(HttpContext.Current.Request["standardid"]);
                    upload.CREATEDID    = int.Parse(getUserType.EmpCode);
                    upload.DIVISIONID   = HttpContext.Current.Request["division"];
                    upload.SUBJECTID    = Convert.ToInt32(HttpContext.Current.Request["subject"]);
                    upload.TERMID       = Convert.ToInt32(HttpContext.Current.Request["term"]);
                    upload.HOMEWORK     = HttpContext.Current.Request["homeworkdescription"];
                    upload.HOMEWORKDATE = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                    upload.TIME         = DateTime.Now.ToShortTimeString();
                    upload.DISPLAY      = 1;
                    upload.ACADEMICYEAR = AcadamicYear.ACADEMICYEAR;

                    upload.FILEPATH = null;

                    //upload.insert_date = DateTime.Now;
                    db.TBLHOMEWORKs.Add(upload);
                    db.SaveChanges();

                    return(new Results
                    {
                        IsSuccess = true,
                        Message = "HomeWork Save Successfully"
                    });
                }
            }
            catch (Exception ex)
            {
                return(new Results
                {
                    IsSuccess = false,
                    Message = ex.ToString()
                });
            }
        }
        public object FileUpload(homeworkparameters obj)
        {
            int Userid           = Convert.ToInt32(HttpContext.Current.Request["Userid"]);
            var Password         = HttpContext.Current.Request["Password"];
            SchoolMainContext db = new ConcreateContext().GetContext(Userid, Password);

            if (db == null)
            {
                return(new Results()
                {
                    IsSuccess = false, Message = "Invalid User"
                });
            }
            var logindetail = db.TBLUSERLOGINs.
                              Where(r => r.UserId == Userid && r.Password == Password && r.STATUS == "ACTIVE")
                              .FirstOrDefault();
            var getUserType = db.VW_GET_USER_TYPE.Where(r => r.UserId == Userid).FirstOrDefault();

            try
            {
                ///Base Url
                string UploadBaseUrl = "";
                var    httpRequest   = HttpContext.Current.Request;
                if (httpRequest.Files.Count > 0)
                {
                    if (logindetail.UserName.StartsWith("NKV"))
                    {
                        UploadBaseUrl = ConfigurationManager.AppSettings["NkvsBaseUrl"];
                    }
                    else if (logindetail.UserName.StartsWith("SXS"))
                    {
                        UploadBaseUrl = ConfigurationManager.AppSettings["StxavierBaseUrl"];
                    }
                    else if (logindetail.UserName.StartsWith("ASM"))
                    {
                        UploadBaseUrl = ConfigurationManager.AppSettings["AsmBaseUrl"];
                    }

                    else if (logindetail.UserName.StartsWith("ASY"))
                    {
                        UploadBaseUrl = ConfigurationManager.AppSettings["AsyBaseUrl"];
                    }
                    else if (logindetail.UserName.StartsWith("NMS"))
                    {
                        UploadBaseUrl = ConfigurationManager.AppSettings["NmsBaseUrl"];
                    }
                    string ftp = UploadBaseUrl;

                    //Upload File Using FTP
                    string ftpFolder = "UPLOADFILE/";
                    byte[] fileBytes = null;
                    string fileName  = "";
                    foreach (string file in httpRequest.Files)
                    {
                        var postedFile = httpRequest.Files[file];
                        fileName = postedFile.FileName;
                        using (StreamReader fileStream = new StreamReader(httpRequest.Files[file].InputStream))
                        {
                            fileBytes = Encoding.UTF8.GetBytes(fileStream.ReadToEnd());
                            fileStream.Close();
                        }

                        try
                        {
                            //Create FTP Request.
                            FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftp + ftpFolder + fileName);
                            request.Method = WebRequestMethods.Ftp.UploadFile;

                            //Enter FTP Server credentials.
                            request.Credentials   = new NetworkCredential("akronsystems", "Password@123");
                            request.ContentLength = fileBytes.Length;
                            request.UsePassive    = true;
                            request.UseBinary     = true;
                            request.ServicePoint.ConnectionLimit = fileBytes.Length;
                            request.EnableSsl = false;
                            Stream requestStream = request.GetRequestStream();
                            requestStream.Write(fileBytes, 0, fileBytes.Length);
                            requestStream.Close();
                            FtpWebResponse response = (FtpWebResponse)request.GetResponse();
                            response.Close();


                            ////Save HomeWork To the Table
                            TBLHOMEWORK upload = new TBLHOMEWORK();
                            upload.STANDARDID   = Convert.ToInt32(HttpContext.Current.Request["standardid"]);
                            upload.CREATEDID    = int.Parse(getUserType.EmpCode);
                            upload.DIVISIONID   = HttpContext.Current.Request["division"];
                            upload.SUBJECTID    = Convert.ToInt32(HttpContext.Current.Request["subject"]);
                            upload.TERMID       = Convert.ToInt32(HttpContext.Current.Request["term"]);
                            upload.HOMEWORK     = HttpContext.Current.Request["homeworkdescription"];
                            upload.HOMEWORKDATE = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                            upload.CREATEDON    = Convert.ToDateTime(DateTime.Now.ToShortDateString());
                            upload.TIME         = DateTime.Now.ToShortTimeString();
                            upload.DISPLAY      = 1;
                            upload.ACADEMICYEAR = "2018-2019";
                            upload.FILEPATH     = fileName;
                            db.TBLHOMEWORKs.Add(upload);
                            db.SaveChanges();

                            ///Save HomeWork Notification



                            TBLNOTIFICATION       objmaster = new TBLNOTIFICATION();
                            TBLNOTIFICATIONDETAIL objdetail = new TBLNOTIFICATIONDETAIL();

                            objmaster.TITLE            = HttpContext.Current.Request["homeworkdescription"];
                            objmaster.NOTIFICATIONDATE = DateTime.Now;
                            objmaster.NOTIFICATIONTIME = DateTime.Now.ToShortTimeString();
                            objmaster.ACADEMICYEAR     = "2018-2019";
                            objmaster.DIVISIONID       = Convert.ToInt32(HttpContext.Current.Request["division"]);
                            objmaster.NOTIFICATIONTYPE = "Homework";
                            db.TBLNOTIFICATIONs.Add(objmaster);
                            db.SaveChanges();
                            objdetail.NOTIFICATIONID = objmaster.NOTIFICATIONID;

                            var DivisionId = Convert.ToInt32(HttpContext.Current.Request["division"]);
                            var getstudent = db.VIEWGETSTUDENTATTs.Where(r => r.DIVISIONID == DivisionId).ToList();
                            if (getstudent == null)
                            {
                                return(new Results
                                {
                                    IsSuccess = false,
                                    Message = "Student Not Found"
                                });
                            }
                            // return getstudent;
                            for (int i = 0; i < getstudent.Count; i++)
                            {
                                TBLNOTIFICATIONDETAIL objnotidetails = new TBLNOTIFICATIONDETAIL();
                                objnotidetails.NOTIFICATIONID = objmaster.NOTIFICATIONID;
                                objnotidetails.STUDENTID      = getstudent[i].STUDENTID;
                                objnotidetails.STATUS         = 0;
                                db.TBLNOTIFICATIONDETAILs.Add(objnotidetails);
                                db.SaveChanges();
                                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("Homework", obj.homeworkdescription, device.DeviceId);
                                    }
                                }
                                //if (smsstatus == "1")
                                //{
                                //    SMSSendTESTDLR(getstudent[i].GMOBILE, objHomework.HOMEWORK);
                                //}
                            }
                            return(new Results
                            {
                                IsSuccess = true,
                                Message = "Homework assign successfully"
                            });
                        }
                        catch (WebException ex)
                        {
                            return(new Results
                            {
                                IsSuccess = false,
                                Message = "Failed to upload File"
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(new Results
                {
                    IsSuccess = false,
                    Message = ex.ToString()
                });
            }


            return(null);
        }