Example #1
0
        public ActionResult AddSchool(tbl_schoolValidation school)
        {
            try
            {
                digital_School.Models.School a = new digital_School.Models.School();

                var userWithSameEmail = db.Schools.Where(m => m.School_Email == school.School_Email).SingleOrDefault(); //checking if the emailid already exits for any user
                if (userWithSameEmail == null)
                {
                    string filename  = Path.GetFileNameWithoutExtension(school.UserImageFIle.FileName);
                    string extension = Path.GetExtension(school.UserImageFIle.FileName);
                    filename = DateTime.Now.ToString("yymmssff") + extension;

                    a.School_Image = "~/FrontEnd/Images/SchoolImage/" + filename;
                    //image ko folder me save krwanay ke leye
                    filename = Path.Combine(Server.MapPath("~/FrontEnd/Images/SchoolImage/"), filename);
                    school.UserImageFIle.SaveAs(filename);
                    a.School_Name      = school.School_Name;
                    a.School_Address   = school.School_Address;
                    a.School_Email     = school.School_Email;
                    a.School_Contactno = school.School_Contactno;
                    a.Password         = school.Password;

                    a.CreatedOn = DateTime.Now;

                    db.Schools.Add(a);
                    db.SaveChanges();
                }

                else
                {
                    ViewBag.Message = "User with this Email Already Exist";
                    return(View());
                }


                int        schoollatestid = a.School_Id;
                loginTable l = new loginTable();
                l.UserId   = schoollatestid;
                l.Name     = a.School_Name;
                l.Password = a.Password;
                l.RoleID   = 2;
                l.Email    = a.School_Email;
                db.loginTables.Add(l);
                db.SaveChanges();
                ModelState.Clear();
                ViewBag.Message = "Data Submitted";

                return(View());
            }
            catch (Exception ex)
            {
                ViewBag.Message = "Not Submitted";
                return(View());
            }
        }
        public ActionResult Profile()
        {
            if (Session["school"] == null)
            {
                return(RedirectToAction("login", "Home", new { area = "" }));
            }
            SchoolDBHandle sadb = new SchoolDBHandle();

            int userid = Convert.ToInt32((Session["school"]));
            var sab    = db.SuperAdmins.Find(userid);

            Session["imgPath"] = sab.ad_imageurl;
            tbl_schoolValidation sa = sadb.GetProfileData(userid);

            return(View(sa));
        }
        public ActionResult ProfileSetting()
        {
            if (Session["school"] == null)
            {
                return(RedirectToAction("Login", "Account", new { area = "" }));
            }
            SchoolDBHandle sadb = new SchoolDBHandle();

            int userid = Convert.ToInt32((Session["school"]));
            var sab    = db.Schools.Find(userid);

            Session["imgPath"]     = sab.School_Image;
            Session["DateCreated"] = sab.CreatedOn;
            tbl_schoolValidation sa = sadb.GetProfileData(userid);

            return(View(sa));
        }
Example #4
0
        public tbl_schoolValidation GetProfileData(int CurrentUserid)
        {
            tbl_schoolValidation school = new tbl_schoolValidation();
            SqlCommand           sc     = new SqlCommand("[Digital_School].[get_SchoolProfileData]", Connections.GetConnection());

            sc.CommandType = CommandType.StoredProcedure;
            sc.Parameters.AddWithValue("@School_Id", CurrentUserid);

            SqlDataReader reader = sc.ExecuteReader();

            //ek hi row return hoga islye
            reader.Read();//return one row only
            school.School_Name      = reader["School_Name"].ToString();
            school.School_Contactno = reader["School_Contactno"].ToString();
            school.School_Image     = reader["School_Image"].ToString();
            school.Password         = reader["Password"].ToString();
            school.School_Email     = reader["School_Email"].ToString();
            school.School_Address   = reader["School_Address"].ToString();

            reader.Close();
            return(school);
        }
        public ActionResult ProfileSetting(tbl_schoolValidation sa)

        {
            School school = new School();

            try
            {
                //loginTable l = new loginTable();
                int userid = Convert.ToInt32((Session["school"]));

                var l = db.loginTables.FirstOrDefault(t => t.UserId == userid);

                //if (ModelState.IsValid)
                //{

                if (sa.UserImageFIle != null)
                {
                    if (l != null)
                    {
                        Session["schoolName"] = sa.School_Name;
                        l.UserId          = userid;
                        l.Name            = sa.School_Name;
                        l.Password        = sa.Password;
                        l.Email           = sa.School_Email;
                        l.RoleID          = 2;
                        db.Entry(l).State = EntityState.Modified;

                        db.SaveChanges();
                    }
                    string filename  = Path.GetFileNameWithoutExtension(sa.UserImageFIle.FileName);
                    string extension = Path.GetExtension(sa.UserImageFIle.FileName);
                    filename = DateTime.Now.ToString("yymmssff") + extension;



                    school.School_Address   = sa.School_Address;
                    school.School_Image     = "~/FrontEnd/Images/SchoolImage/" + filename;
                    school.School_Name      = sa.School_Name;
                    school.School_Contactno = sa.School_Contactno;

                    school.School_Email = sa.School_Email;
                    school.Password     = sa.Password;
                    school.School_Id    = userid;
                    school.CreatedOn    = Convert.ToDateTime(Session["DateCreated"]);



                    if (extension.ToLower() == ".jpg" || extension.ToLower() == ".jpeg" || extension.ToLower() == ".png")
                    {
                        if (sa.UserImageFIle.ContentLength <= 1000000)
                        {
                            db.Entry(school).State = EntityState.Modified;



                            string oldImgPath = Request.MapPath(Session["imgPath"].ToString());

                            if (db.SaveChanges() > 0)
                            {
                                filename = Path.Combine(Server.MapPath("~/FrontEnd/Images/SchoolImage/"), filename);
                                sa.UserImageFIle.SaveAs(filename);
                                if (System.IO.File.Exists(oldImgPath))
                                {
                                    System.IO.File.Delete(oldImgPath);
                                }


                                ViewBag.Message = "Data Updated";
                                return(RedirectToAction("ProfileSetting"));
                            }
                        }
                        else
                        {
                            ViewBag.msg = "File Size must be Equal or less than 1mb";
                        }
                    }
                    else
                    {
                        ViewBag.msg = "Inavlid File Type";
                    }
                }

                //}
                else
                {
                    school.School_Image = Session["imgPath"].ToString();
                    if (l != null)
                    {
                        Session["schoolName"] = sa.School_Name;
                        l.UserId   = userid;
                        l.Name     = sa.School_Name;
                        l.Password = sa.Password;
                        l.Email    = sa.School_Email;

                        l.RoleID          = 2;
                        db.Entry(l).State = EntityState.Modified;
                        db.SaveChanges();
                    }
                    school.School_Name      = sa.School_Name;
                    school.School_Email     = sa.School_Email;
                    school.Password         = sa.Password;
                    school.CreatedOn        = Convert.ToDateTime(Session["DateCreated"]);
                    school.School_Contactno = sa.School_Contactno;
                    school.School_Address   = sa.School_Address;
                    school.School_Id        = userid;
                    db.Entry(school).State  = EntityState.Modified;

                    if (db.SaveChanges() > 0)
                    {
                        ViewBag.Message = "Data Updated";
                        return(RedirectToAction("ProfileSetting"));
                    }
                }
            }


            catch (Exception ex)
            {
                ViewBag.Message = "Not Updated";
                return(View());
            }
            return(View());
        }