Beispiel #1
0
        public ActionResult oneTimePin(OneTimePin model)
        {
            if (ModelState.IsValid)
            {
                var newStudent = (Registered_Person)Session["newStudent"];
                var personRole = new Person_Role();

                personRole.Person_ID = newStudent.Person_ID;
                personRole.Role_ID   = (from r in db.Roles
                                        where r.Role_Name == "Student"
                                        select r.Role_ID).FirstOrDefault();

                db.Registered_Person.Add(newStudent);
                db.Person_Role.Add(personRole);
                db.SaveChanges();

                //record action
                global.addAudit("Students", "Students: Registration", "Create", newStudent.Person_ID);

                Session.Remove("newStudent");
                Session.Remove("OTP");

                TempData["Message"]    = "Succesfully created an account!";
                TempData["classStyle"] = "success";

                return(RedirectToAction("Login", "Account"));
            }
            else
            {
                return(View());
            }
        }
Beispiel #2
0
 public ActionResult Create(PersonTypeAddModel model)
 {
     ViewBag.ErrorMsg       = "";
     TempData["SuccessMsg"] = "";
     if (ModelState.IsValid)
     {
         var query = (from p in db.Person_Type
                      where (p.Person_Type1.ToLower() == model.person_type.ToLower())
                      select p);
         if (query.Count() != 0)
         {
             ViewBag.ErrorMsg = "Person Type exists, please provide a different Person Type";
             return(View(model));
         }
         Person_Type persontype = new Person_Type();
         persontype.Person_Type1 = model.person_type;
         db.Person_Type.Add(persontype);
         db.SaveChanges();
         TempData["SuccessMsg"] = "Person Type was added successfully";
         return(RedirectToAction("Index"));
     }
     else
     {
         ViewBag.ErrorMsg = "";
         return(View());
     }
 }
Beispiel #3
0
        public ActionResult Create(MemberCreateVM viewModel)
        {
            //Role id has been hardcoded to represent student (4)
            TempData["Show"] = false;
            if (db.Registered_Person.Any(x => x.Person_ID == viewModel.person_id))
            {
                ModelState.AddModelError("person_id", "Username is already registered");
            }
            if (!db.Registered_Person.Any(x => x.Person_ID.StartsWith("p")))
            {
                ModelState.AddModelError("person_id", "Username must start with a 'p' and follow with 8 digits");
            }
            if (ModelState.IsValid)
            {
                string password = Membership.GeneratePassword(5, 1);
                var    hashed   = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
                var    mem      = new Registered_Person();
                mem.Person_ID       = viewModel.person_id;
                mem.Person_Name     = viewModel.person_name;
                mem.Person_Surname  = viewModel.person_surname;
                mem.Person_Type     = "Student";
                mem.Person_Password = hashed;
                mem.Person_Registration_DateTime = DateTime.Now;
                mem.Person_Email = viewModel.person_email;
                db.Registered_Person.Add(mem);
                var pRole = new Person_Role();
                pRole.Person_ID = viewModel.person_id;
                pRole.Role_ID   = 4;

                db.Person_Role.Add(pRole);

                //Email start
                MailMessage message = new MailMessage();
                SmtpClient  client  = new SmtpClient();
                client.Host  = "smtp.gmail.com";
                client.Port  = 587;
                message.From = new MailAddress("*****@*****.**");
                message.To.Add(viewModel.person_email);
                message.Subject              = "Member Registerstration";
                message.Body                 = "Hi, " + viewModel.person_id + " you have been registered to UP Library Assistant by an Admin, use your UP username to login, your password is: " + password;
                message.IsBodyHtml           = true;
                client.EnableSsl             = true;
                client.UseDefaultCredentials = true;
                client.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "tester123#");
                client.Send(message);
                //Email end

                db.SaveChanges();
                TempData["Msg"]   = "New member created successfully.";
                TempData["Show"]  = true;
                TempData["color"] = "alert-success";
                return(RedirectToAction("Index"));
            }
            TempData["Show"]  = true;
            TempData["color"] = "alert-warning";
            TempData["Msg"]   = "Something went wrong.";
            return(View(viewModel));
        }
Beispiel #4
0
        public ActionResult Logout()
        {
            FormsAuthentication.SignOut();

            //var update person session log
            var session = db.Person_Session_Log.Where(q => q.Person_ID == User.Identity.Name).OrderByDescending(d => d.Login_DateTime).First();

            session.Logout_DateTime = DateTime.Now;
            db.Entry(session).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
Beispiel #5
0
        public ActionResult Login(Login l, string ReturnUrl = "")
        {
            if (ModelState.IsValid)
            {
                var  hashedPass             = FormsAuthentication.HashPasswordForStoringInConfigFile(l.Person_Password, "MD5");
                bool isValidUser            = Membership.ValidateUser(l.Person_ID, hashedPass);
                LibraryAssistantEntities db = new LibraryAssistantEntities();
                if (isValidUser)
                {
                    Registered_Person registered_person = null;
                    registered_person = db.Registered_Person.Where(a => a.Person_ID.Equals(l.Person_ID)).FirstOrDefault();
                    if (registered_person != null)
                    {
                        //initiate an instance of a passable registered student
                        Registered_Person passablePerson = new Registered_Person();
                        passablePerson.Person_ID       = registered_person.Person_ID;
                        passablePerson.Person_Name     = registered_person.Person_Name;
                        passablePerson.Person_Surname  = registered_person.Person_Surname;
                        passablePerson.Person_Email    = registered_person.Person_Email;
                        passablePerson.Person_Password = registered_person.Person_Password;

                        JavaScriptSerializer js          = new JavaScriptSerializer();
                        string data                      = js.Serialize(passablePerson);
                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, registered_person.Person_ID, DateTime.Now, DateTime.Now.AddMinutes(20), false, data);
                        string     encToken              = FormsAuthentication.Encrypt(ticket);
                        HttpCookie authCookies           = new HttpCookie(FormsAuthentication.FormsCookieName, encToken);
                        Response.Cookies.Add(authCookies);

                        Person_Session_Log newSession = new Person_Session_Log();

                        newSession.Person_ID       = l.Person_ID;
                        newSession.Login_DateTime  = DateTime.Now;
                        newSession.Logout_DateTime = newSession.Login_DateTime.AddMinutes(20);
                        db.Person_Session_Log.Add(newSession);

                        db.SaveChanges();

                        Session["loginSession"] = newSession;

                        if (ReturnUrl != "")
                        {
                            return(Redirect(ReturnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                }
                else
                {
                    TempData["Message"]    = "Invalid Login Details!";
                    TempData["classStyle"] = "danger";
                    return(View());
                }
            }
            ModelState.Remove("Person_Password");
            return(View());
        }
Beispiel #6
0
        public ActionResult captureDetails()
        {
            //assign session variables and cast

            var venue = (Venue)Session["venueSelect"];

            var details = (DiscussionRoomBooking)Session["details"];

            //create instance of new Venue_Booking object
            Venue_Booking        vb  = new Venue_Booking();
            Venue_Booking_Person vbp = new Venue_Booking_Person();

            //get booking seq of discussion room
            var BookingTypeSeq = (from a in db.Booking_Type
                                  where a.Booking_Type_Name.Equals("Discussion Room")
                                  select a.Booking_Type_Seq).FirstOrDefault();

            //set properties of venue_booking object to submitted properties
            vb.Venue_Booking_Name             = "null"; //not sure what this value represents
            vb.DateTime_From                  = details.date;
            vb.DateTime_To                    = details.endDate;
            vb.Send_Email_To_Topic_Person_Ind = 0; //no email
            vb.Max_Bookings                   = 0; //doesn't apply to discussion room bookings
            vb.Exclusive_ind                  = 0; //discussion room sessions cant be exclusive
            vb.Description                    = "Discussion Room Session";
            vb.Booking_Type_Seq               = BookingTypeSeq;
            vb.Topic_Seq         = 1;
            vb.Booking_Status    = "Active";
            vb.Venue_ID          = venue.Venue_ID;
            vb.Building_Floor_ID = venue.Building_Floor_ID;
            vb.Building_ID       = venue.Building_ID;
            vb.Campus_ID         = venue.Campus_ID;

            //add new venue booking to database
            db.Venue_Booking.Add(vb);

            //record action
            global.addAudit("Bookings", "Booking: Discussion Room Booking", "Create", User.Identity.Name);

            db.SaveChanges();

            //get booking seq of booking just created

            var bookingSeq = vb.Venue_Booking_Seq;

            //set properties of venue booking person object
            vbp.Venue_Booking_Seq = bookingSeq;
            vbp.Person_ID         = details.person_id;
            vbp.Attendee_Type     = "Student";
            vbp.Attendee_Status   = "Active";

            //add new venue booking person object to database
            db.Venue_Booking_Person.Add(vbp);
            db.SaveChanges();

            //get return url
            var site = Url.Action("ViewBookings", "Booking");

            return(Content(site));
        }
Beispiel #7
0
        public PartialViewResult AddPersonTopic(AddPersonTopicModel model)
        {
            var topicList = from a in db.Topics
                            join b in db.Person_Topic on a.Topic_Seq equals b.Topic_Seq
                            where b.Person_ID.Equals(User.Identity.Name)
                            select a;

            var peopleDifference = from person2 in db.Topics
                                   where !(
                from person1 in topicList
                select person1.Topic_Seq
                ).Contains(person2.Topic_Seq)
                                   select person2;

            if (ModelState.IsValid)
            {
                Person_Topic a = new Person_Topic();
                a.Topic_Seq = model.Topic_Seq;
                a.Person_ID = User.Identity.Name;
                db.Person_Topic.Add(a);
                db.SaveChanges();
                TempData["Message"] = "Topic Added";
                if (peopleDifference.Count() == 0)
                {
                    ViewBag.Topic_Seq = null;
                    return(PartialView());
                }
                else
                {
                    ViewBag.Topic_Seq = new SelectList((IEnumerable <Topic>)peopleDifference, "Topic_Seq", "Topic_Name");
                    return(PartialView());
                }
            }
            else
            {
                ViewBag.Topic_Seq = new SelectList((IEnumerable <Topic>)peopleDifference, "Topic_Seq", "Topic_Name");
                return(PartialView());
            }
        }
Beispiel #8
0
        public ActionResult Create_Back_From_Create_Question(string Topic_Name, string Topic_Des)
        {
            Question_Topic question_Topic = db.Question_Topic.Where(X => X.Topic_Name == Topic_Name).Single();

            //// -------------------------------Action Log ----------------------------------------//
            //string name = db.Question_Topic.Where(X => X.Topic_Seq == question_Topic.Topic_Seq).Select(Y => Y.Topic_Name).Single();


            //db.Person_Session_Action_Log.Remove(db.Person_Session_Action_Log.Where(X => X.Action_Performed == "Created question topic: " + name).Single());
            //db.SaveChanges();
            //// -------------------------------Action Log ----------------------------------------//


            db.Question_Topic.Remove(question_Topic);
            db.SaveChanges();


            ViewBag.Topic_Name = Topic_Name;
            ViewBag.Topic_Des  = Topic_Des;
            return(View("Create"));
        }
Beispiel #9
0
        void Session_End(object sender, EventArgs e)
        {
            Application.Lock();
            var online = (int)Application["OnlineUsers"];

            Application["OnlineUsers"] = online - 1;
            Application.UnLock();

            try
            {
                LibraryAssistantEntities db = new LibraryAssistantEntities();
                //update session end time
                var session = db.Person_Session_Log.Where(p => p.Person_ID == User.Identity.Name).OrderByDescending(d => d.Login_DateTime).First();
                if (session.Logout_DateTime == session.Login_DateTime.AddMinutes(20))
                {
                    session.Logout_DateTime = DateTime.Now;
                    db.Entry(session).State = System.Data.Entity.EntityState.Modified;
                    db.SaveChanges();
                }
            }
            catch
            {
            }
        }
Beispiel #10
0
        public ActionResult AddFile(AddFileModel model)
        {
            //check if model state is valid
            if (ModelState.IsValid)
            {
                //get uploaded file filename
                var filename = Path.GetFileName(model.uploadFile.FileName);
                //get uploaded file path
                var path = Path.Combine(Server.MapPath("~/App_Data/Uploads"), filename);
                //determine the uploaded file extension
                var extension = Path.GetExtension(model.uploadFile.FileName);
                //check if the file uploaded is a valid extension
                if (System.IO.File.Exists(path))
                {
                    TempData["Message"]      = "Uploaded file already exists";
                    TempData["classStyle"]   = "warning";
                    model.uploadFile         = null;
                    ViewBag.Category_ID      = new SelectList(db.Document_Category, "Category_ID", "Category_Name");
                    ViewBag.Document_Type_ID = new SelectList(db.Document_Type, "Document_Type_ID", "Document_Type_Name");
                    return(View(model));
                }
                else
                {
                    var validExtension = db.Document_Extension.Where(m => m.Extension_Type.Equals(extension)).FirstOrDefault();
                    if (validExtension != null)
                    {
                        //create a new instance of a document_repository object
                        Document_Repository a = new Document_Repository();
                        //add details of the file to a document_repository object
                        a.Document_Name         = model.Document_Name;
                        a.Description           = model.Description;
                        a.Category_ID           = model.Category_ID;
                        a.Document_Type_ID      = model.Document_Type_ID;
                        a.Directory_Path        = path;
                        a.Document_Extension_ID = validExtension.Document_Extension_ID;
                        a.Document_Status       = "Active";
                        db.Document_Repository.Add(a);
                        db.SaveChanges();

                        var sessionLog = db.Person_Session_Log.Where(p => p.Person_ID == User.Identity.Name).OrderByDescending(p => p.Login_DateTime).FirstOrDefault();

                        Document_Access_Log ac = new Document_Access_Log();
                        ac.Access_DateTime = DateTime.Now;
                        ac.Document_Seq    = a.Document_Seq;
                        ac.Session_ID      = sessionLog.Session_ID;

                        db.Document_Access_Log.Add(ac);
                        db.SaveChanges();

                        //record action
                        global.addAudit("Repository", "Repository: Add File", "Create", User.Identity.Name);

                        //save file to server
                        model.uploadFile.SaveAs(path);
                        TempData["Message"]    = "File successfully uploaded";
                        TempData["classStyle"] = "success";
                        return(RedirectToAction("ViewFile"));
                    }
                    else
                    {
                        ViewBag.Category_ID      = new SelectList(db.Document_Category, "Category_ID", "Category_Name");
                        ViewBag.Document_Type_ID = new SelectList(db.Document_Type, "Document_Type_ID", "Document_Type_Name");
                        return(View());
                    }
                }
            }
            ViewBag.Category_ID      = new SelectList(db.Document_Category, "Category_ID", "Category_Name");
            ViewBag.Document_Type_ID = new SelectList(db.Document_Type, "Document_Type_ID", "Document_Type_Name");
            return(View());
        }
Beispiel #11
0
        public ActionResult Create(RoleModel role)
        {
            var       RoleAction = db.Role_Action;
            RoleModel roleModel  = new RoleModel();

            roleModel.RoleActions = new List <RoleActionModel>();
            foreach (var a in RoleAction)
            {
                RoleActionModel ra = new RoleActionModel();
                ra.CreateInd  = a.Create_Ind;
                ra.ReadInd    = a.Read_Ind;
                ra.UpdateInd  = a.Update_Ind;
                ra.DeleteInd  = a.Delete_Ind;
                ra.ActionId   = a.Action_ID;
                ra.RoleId     = a.Role_ID;
                ra.ActionName = a.Action.Action_Name;
                roleModel.RoleActions.Add(ra);
            }
            var distinctActions =
                roleModel.RoleActions.GroupBy(x => x.ActionId)
                .Select(g => g.FirstOrDefault())
                .ToList();

            roleModel.RoleActions = distinctActions;
            try
            {
                int  Count  = 0;
                bool create = true;
                bool read   = true;
                bool update = true;
                bool delete = true;
                ViewBag.ErrorMsg = "";
                var query = (from q in db.Roles
                             where q.Role_Name.ToLower() == role.RoleName.ToLower()
                             select q);
                if (query.Count() != 0)
                {
                    ViewBag.ErrorMsg = "The role name exists, please provide a different role name";
                    return(View(roleModel));
                }
                Role r = new Role();
                r.Role_Name = role.RoleName;
                db.Roles.Add(r);
                foreach (var o in role.RoleActions)
                {
                    Role_Action ra = new Role_Action();
                    ra.Action_ID  = o.ActionId;
                    ra.Role_ID    = r.Role_ID;
                    ra.Create_Ind = o.CreateInd;
                    ra.Read_Ind   = o.ReadInd;
                    ra.Update_Ind = o.UpdateInd;
                    ra.Delete_Ind = o.DeleteInd;
                    db.Role_Action.Add(ra);
                    create = ra.Create_Ind;
                    if (create == false)
                    {
                        Count++;
                    }
                    read = ra.Read_Ind;
                    if (read == false)
                    {
                        Count++;
                    }
                    update = ra.Update_Ind;
                    if (update == false)
                    {
                        Count++;
                    }
                    delete = ra.Delete_Ind;
                    if (delete == false)
                    {
                        Count++;
                    }
                    if (Count == (role.RoleActions.Count() * 4))
                    {
                        ViewBag.Error = "Role must be assigned at least 1 action";
                        return(View(roleModel));
                    }
                }
                db.SaveChanges();

                return(RedirectToAction("Index", "Role"));
            }
            catch
            {
                return(View(roleModel));
            }
        }
Beispiel #12
0
        public ActionResult Create(EmployeeAddModel viewModel)
        {
            TempData["Show"] = false;
            var topicchecklist = (List <TopicCheck>)Session["Topic_Checked"];

            if (db.Registered_Person.Any(x => x.Person_ID == viewModel.person_id))
            {
                ModelState.AddModelError("person_id", "Username is already registered");
            }
            if (!db.Registered_Person.Any(x => x.Person_ID.StartsWith("p")))
            {
                ModelState.AddModelError("person_id", "Username must start with a 'p' and follow with 8 digits");
            }
            if (ModelState.IsValid)

            {
                string password = Membership.GeneratePassword(5, 1);
                var    hashed   = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
                var    emp      = new Registered_Person();
                emp.Person_ID       = viewModel.person_id;
                emp.Person_Name     = viewModel.person_name;
                emp.Person_Surname  = viewModel.person_surname;
                emp.Person_Type     = "Employee";
                emp.Person_Password = hashed;
                emp.Person_Registration_DateTime = DateTime.Now;
                emp.Person_Email = viewModel.person_email;
                db.Registered_Person.Add(emp);
                foreach (var item in viewModel.role_check)
                {
                    var prole = new Person_Role();
                    if (item.role_ind)
                    {
                        prole.Role_ID   = item.role_id;
                        prole.Person_ID = emp.Person_ID;
                        db.Person_Role.Add(prole);
                    }
                }
                try
                {
                    foreach (var item in topicchecklist)
                    {
                        var trainertopic = new Trainer_Topic();
                        if (item.topic_ind)
                        {
                            trainertopic.Person_ID = emp.Person_ID;
                            trainertopic.Topic_Seq = item.topic_seq;
                            db.Trainer_Topic.Add(trainertopic);
                        }
                    }
                }
                catch
                {
                }

                //Email start
                MailMessage message = new MailMessage();
                SmtpClient  client  = new SmtpClient();
                client.Host = "smtp.gmail.com";
                client.Port = 587;

                message.From = new MailAddress("*****@*****.**");
                message.To.Add(viewModel.person_email);
                message.Subject              = "Employee Registration";
                message.Body                 = "Hi, " + viewModel.person_id + " you have been registered to UP Library Assistant by an Admin, use your UP username to login, your password is: " + password;
                message.IsBodyHtml           = true;
                client.EnableSsl             = true;
                client.UseDefaultCredentials = true;
                client.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "tester123#");
                client.Send(message);
                //Email end

                db.SaveChanges();
                TempData["Msg"]   = "New employee created successfully.";
                TempData["Show"]  = true;
                TempData["color"] = "alert-success";
                return(RedirectToAction("Index"));
            }
            ViewBag.Check1 = true;
            ViewBag.Check2 = true;
            viewModel.role = (db.Roles
                              .Include(i => i.Role_Action.Select(x => x.Action))).ToList();
            var rolechecklist = new List <RoleCheck>();

            for (int i = 0; i < viewModel.role.Count(); i++)
            {
                var roleCheck = new RoleCheck();
                roleCheck.role_id = viewModel.role[i].Role_ID;
                rolechecklist.Add(roleCheck);
            }
            viewModel.role_check = rolechecklist;
            ViewBag.Person_Type  = new SelectList(db.Person_Type, "Person_Type1", "Person_Type1", 2);
            TempData["Msg"]      = "Something went wrong.";
            TempData["Show"]     = true;
            TempData["color"]    = "alert-success";
            return(View(viewModel));
        }