Ejemplo n.º 1
0
        public ActionResult SingleWarden(int id)
        {
            ViewBag.List    = new List <tblHostel>();
            ViewBag.Rooms   = db.tblRooms.ToList();
            ViewBag.Hostels = db.tblHostels.ToList();
            tblWarden tb = db.tblWardens.Where(x => x.WardenId == id).FirstOrDefault();

            return(View(tb));
        }
Ejemplo n.º 2
0
        public ActionResult Registration(StudentRegistrationViewModel ts = null, WardenRegistrationViewModel tw = null)
        {
            tbluser us = new tbluser();

            if (ts.StudentUserName != null)
            {
                if (ts.StudentId == 0)
                {
                    tblStudent         student = new tblStudent();
                    HttpPostedFileBase pic     = Request.Files["StudentPhoto"];
                    HttpPostedFileBase avt     = Request.Files["AvatarPhoto"];
                    student.UserName         = ts.StudentUserName;
                    student.StudentName      = ts.StudentName;
                    student.PermanentAddress = ts.PermanentAddress;
                    student.TemporaryAddress = ts.TemporaryAddress;
                    student.Phone            = ts.StudentPhone;
                    student.Email            = ts.StudentEmail;
                    student.Education        = ts.Education;
                    student.DOB         = ts.DOB;
                    student.Age         = Convert.ToInt32(DateTime.Now.Year) - Convert.ToInt32(student.DOB.Value.Year);
                    student.Photo       = pic.FileName;
                    student.AvatarPhoto = avt.FileName;
                    student.UserName    = ts.StudentUserName;
                    student.Password    = ts.StudentPassword;
                    us.UserName         = ts.StudentUserName;
                    us.Password         = ts.StudentPassword;
                    us.Email            = ts.StudentEmail;
                    if (pic.ContentLength > 0)
                    {
                        pic.SaveAs(Path.Combine(Server.MapPath("~/Images/Student"), pic.FileName));
                    }
                    if (avt.ContentLength > 0)
                    {
                        avt.SaveAs(Path.Combine(Server.MapPath("~/Images/Student"), avt.FileName));
                    }
                    db.tblusers.Add(us);
                    db.tblStudents.Add(student);
                    db.SaveChanges();
                    tbluser     tb = db.tblusers.Where(x => x.UserName == student.UserName).FirstOrDefault();
                    tblUserRole tr = new tblUserRole();
                    tr.UserId = tb.UserId;
                    tr.RoleId = 2;
                    db.tblUserRoles.Add(tr);
                    db.SaveChanges();
                }
                else
                {
                    StudentRegistrationViewModel sm = ts;
                    tblStudent         student      = db.tblStudents.Where(x => x.StudentId == sm.StudentId).FirstOrDefault();
                    HttpPostedFileBase pic          = Request.Files["StudentPhoto"];
                    HttpPostedFileBase avt          = Request.Files["AvatarPhoto"];
                    student.UserName         = sm.StudentUserName;
                    student.StudentName      = sm.StudentName + " " + sm.StudentSurName;
                    student.PermanentAddress = sm.PermanentAddress;
                    student.TemporaryAddress = sm.TemporaryAddress;
                    student.Phone            = sm.StudentPhone;
                    student.Email            = sm.StudentEmail;
                    student.Education        = sm.Education;
                    student.DOB         = sm.DOB;
                    student.Testomonial = sm.Testomonial;
                    student.Age         = Convert.ToInt32(DateTime.Now.Year) - Convert.ToInt32(student.DOB.Value.Year);
                    if (pic.ContentLength > 0)
                    {
                        System.IO.File.Delete(Path.Combine(Server.MapPath("~/Images/Student/"), sm.StudentPhoto));
                        student.Photo = pic.FileName;
                        avt.SaveAs(Path.Combine(Server.MapPath("~/Images/Student/"), pic.FileName));
                    }
                    if (avt.ContentLength > 0)
                    {
                        System.IO.File.Delete(Path.Combine(Server.MapPath("~/Images/Student/"), sm.AvatarPhoto));
                        student.AvatarPhoto = avt.FileName;
                        avt.SaveAs(Path.Combine(Server.MapPath("~/Images/Student/"), avt.FileName));
                    }
                    student.UserName = sm.StudentUserName;
                    student.Password = sm.StudentPassword;
                    foreach (var item in db.tblusers.ToList())
                    {
                        if (item.UserName == User.Identity.Name)
                        {
                            item.UserName = sm.StudentUserName;
                            item.Email    = sm.StudentEmail;
                            item.Password = sm.StudentPassword;
                        }
                    }
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Opening"));
                }
            }

            if (tw.UserName != null)
            {
                if (tw.WardenId == 0)
                {
                    tblWarden          warden = new tblWarden();
                    HttpPostedFileBase fup    = Request.Files["Photo"];
                    var filename = fup.FileName;
                    warden.WardenName    = tw.WardenName + " " + tw.WardenSurName;
                    warden.WardenAddress = tw.WardenAddress;
                    warden.WardenPhone   = tw.WardenPhone;
                    warden.Email         = tw.Email;
                    warden.Photo         = filename;
                    warden.UserName      = tw.UserName;
                    warden.Password      = tw.Password;
                    us.UserName          = tw.UserName;
                    us.Password          = tw.Password;
                    us.Email             = tw.Email;
                    if (fup.ContentLength > 0)
                    {
                        fup.SaveAs(Path.Combine(Server.MapPath("~/Images/Warden/"), fup.FileName));
                    }
                    db.tblusers.Add(us);
                    db.tblWardens.Add(warden);
                    db.SaveChanges();
                    tbluser tb = db.tblusers.Where(x => x.UserName == warden.UserName).FirstOrDefault();

                    tblUserRole tr = new tblUserRole();
                    tr.UserId = tb.UserId;
                    tr.RoleId = 3;
                    db.tblUserRoles.Add(tr);
                    db.SaveChanges();
                }
                else
                {
                    tblWarden          warden = db.tblWardens.Where(x => x.WardenId == tw.WardenId).FirstOrDefault();
                    HttpPostedFileBase fup    = Request.Files["Photo"];
                    warden.WardenName    = tw.WardenName + " " + tw.WardenSurName;
                    warden.WardenAddress = tw.WardenAddress;
                    warden.WardenPhone   = tw.WardenPhone;
                    warden.Email         = tw.Email;
                    warden.Password      = tw.Password;
                    if (fup.ContentLength > 0)
                    {
                        System.IO.File.Delete(Path.Combine(Server.MapPath("~/Images/Warden/"), tw.Photo));
                        warden.Photo = fup.FileName;
                        fup.SaveAs(Path.Combine(Server.MapPath("~/Images/Warden/"), fup.FileName));
                    }

                    warden.UserName = tw.UserName;
                    foreach (var item in db.tblusers.ToList())
                    {
                        if (item.UserName == User.Identity.Name)
                        {
                            item.Password = tw.Password;
                            item.UserName = tw.UserName;
                            item.Email    = tw.Email;
                        }
                    }
                    db.SaveChanges();
                    return(RedirectToAction("Index", "Opening"));
                }
            }
            return(RedirectToAction("Login", "Account"));
        }