예제 #1
0
        public ActionResult Edit([Bind(Include = "Topic_Seq,Topic_Name,Description")] Question_Topic question_Topic)
        {
            if (ModelState.IsValid)
            {
                if (AreThereDuplicatesTopics(question_Topic.Topic_Name))
                {
                    if (db.Question_Topic.Where(X => X.Topic_Seq == question_Topic.Topic_Seq).Select(Y => Y.Topic_Name).Single() == question_Topic.Topic_Name)
                    {
                        db.Entry(question_Topic).State = EntityState.Modified;
                        db.SaveChanges();

                        // -------------------------------Action Log ----------------------------------------//
                        string name = db.Question_Topic.Where(X => X.Topic_Seq == question_Topic.Topic_Seq).Select(Y => Y.Topic_Name).Single();
                        Person_Session_Action_Log psal = new Person_Session_Action_Log();
                        psal.Action_DateTime  = DateTime.Now;
                        psal.Action_ID        = 11;
                        psal.Session_ID       = db.Person_Session_Log.Select(Y => Y.Session_ID).Max();
                        psal.Action_Performed = "Question topic: " + name;
                        psal.Crud_Operation   = "Edit";
                        db.Person_Session_Action_Log.Add(psal);
                        db.SaveChanges();
                        // -------------------------------Action Log ----------------------------------------//


                        ViewBag.Topic = question_Topic.Topic_Seq;
                        return(View("Edit_Some_More"));
                    }
                    else
                    {
                        ModelState.AddModelError("Topic_Name", "This topic already exists. Please choose another topic name.");
                        ViewBag.Topic_Name  = question_Topic.Topic_Name;
                        ViewBag.Description = question_Topic.Description;
                        return(View("Edit"));
                    }
                }
                else
                {
                    db.Entry(question_Topic).State = EntityState.Modified;
                    db.SaveChanges();


                    // -------------------------------Action Log ----------------------------------------//
                    string name = db.Question_Topic.Where(X => X.Topic_Seq == question_Topic.Topic_Seq).Select(Y => Y.Topic_Name).Single();
                    Person_Session_Action_Log psal = new Person_Session_Action_Log();
                    psal.Action_DateTime  = DateTime.Now;
                    psal.Action_ID        = 11;
                    psal.Session_ID       = db.Person_Session_Log.Select(Y => Y.Session_ID).Max();
                    psal.Crud_Operation   = "Edit";
                    psal.Action_Performed = "Question topic: " + name;
                    db.Person_Session_Action_Log.Add(psal);
                    db.SaveChanges();
                    // -------------------------------Action Log ----------------------------------------//

                    ViewBag.Topic = question_Topic.Topic_Seq;
                    return(View("Edit_Some_More"));
                }
            }
            return(View(question_Topic));
        }
예제 #2
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"));
        }
예제 #3
0
 public ActionResult Edit(string id, PersonTypeEditModel model)
 {
     TempData["ErrorMsg"]   = "";
     TempData["SuccessMsg"] = "";
     if (ModelState.IsValid)
     {
         var query = (from pt in db.Person_Type
                      where pt.Person_Type1.ToLower() == model.person_type.Person_Type1.ToLower()
                      select pt);
         if (query.Count() == 1)
         {
             ViewBag.ErrorMsg = "The Person Type exists, please provide a differernt Person Type";
             return(View(model));
         }
         Person_Type person_type = db.Person_Type.Find(id);
         person_type.Person_Type1    = model.person_type.Person_Type1;
         db.Entry(person_type).State = EntityState.Modified;
         db.SaveChanges();
         TempData["SuccessMsg"] = "The Person Type was updated successfully";
         return(RedirectToAction("Index"));
     }
     else
     {
         ViewBag.ErrorMsg = "Person Type invalid";
         return(View(model));
     }
 }
예제 #4
0
        public ActionResult Edit(string id, EmployeeEditModel viewModel)
        {
            var topicchecks = (List <TopicCheck>)Session["TopicChecked"];

            //TODO: validate to make sure at least one role is selected
            if (ModelState.IsValid)
            {
                Registered_Person rp = db.Registered_Person.Find(id);
                rp.Person_ID = id;

                rp.Person_Name    = viewModel.person_name;
                rp.Person_Surname = viewModel.person_surname;
                rp.Person_Email   = viewModel.person_email;

                rp.Person_Type     = "Employee";
                db.Entry(rp).State = EntityState.Modified;
                var roleRemove = db.Person_Role.Where(x => x.Person_ID == id);
                foreach (var item in roleRemove)
                {
                    db.Person_Role.Remove(item);
                }
                foreach (var item in viewModel.emprolecheckeditlist)
                {
                    if (item.role_ind == true)
                    {
                        var pRole = new Person_Role();
                        pRole.Person_ID = id;
                        pRole.Role_ID   = item.role_id;
                        db.Person_Role.Add(pRole);
                    }
                }
                var trainerRemove = db.Trainer_Topic.Where(x => x.Person_ID == id);
                foreach (var item in trainerRemove)
                {
                    db.Trainer_Topic.Remove(item);
                }

                if (viewModel.emprolecheckeditlist.Where(x => x.role_id == 7).Where(y => y.role_ind == true).Any())
                {
                    foreach (var item in topicchecks)
                    {
                        if (item.topic_ind == true)
                        {
                            var tTopic = new Trainer_Topic();
                            tTopic.Person_ID = id;
                            tTopic.Topic_Seq = item.topic_seq;
                            db.Trainer_Topic.Add(tTopic);
                        }
                    }
                }
                db.SaveChanges();
            }
            TempData["Check2"]  = false;
            ViewBag.Person_Type = new SelectList(db.Person_Type, "Person_Type1", "Person_Type1", 2);
            return(RedirectToAction("Index"));
        }
예제 #5
0
 public ActionResult Edit([Bind(Include = "Person_ID,Topic_Seq")] Person_Topic person_Topic)
 {
     if (ModelState.IsValid)
     {
         db.Entry(person_Topic).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.Person_ID = new SelectList(db.Registered_Person, "Person_ID", "Person_Name", person_Topic.Person_ID);
     ViewBag.Topic_Seq = new SelectList(db.Topics, "Topic_Seq", "Topic_Name", person_Topic.Topic_Seq);
     return(View(person_Topic));
 }
예제 #6
0
        public ActionResult UpdateDetails(UpdatePersonModel model)
        {
            if (ModelState.IsValid)
            {
                var identity = User.Identity.Name;
                var count    = db.Registered_Person.Count(me => me.Person_Email == model.Person_Email && me.Person_ID != identity);

                if (count == 0)
                {
                    var registered_Person = (from a in db.Registered_Person
                                             where a.Person_ID == identity
                                             select a).FirstOrDefault();

                    registered_Person.Person_Name    = model.Person_Name;
                    registered_Person.Person_Surname = model.Person_Surname;
                    registered_Person.Person_Email   = model.Person_Email;


                    db.Entry(registered_Person).State = EntityState.Modified;
                    db.SaveChanges();

                    //record action
                    global.addAudit("Students", "Students: Update Profile", "Update", User.Identity.Name);

                    TempData["Message"]    = "Details successfully updated!";
                    TempData["classStyle"] = "success";
                    return(RedirectToAction("Details"));
                }
                else
                {
                    TempData["Message"] = "Email address already exists on the system";
                    return(View(model));
                }
            }

            return(View(model));
        }
예제 #7
0
        public ActionResult captureCancel()
        {
            var a = (BookingDetailsModel)Session["selectedBookingDetails"];

            //get selected booking object from database
            var cancelledBooking       = db.Venue_Booking.Where(b => b.Venue_Booking_Seq.Equals(a.booking_seq)).FirstOrDefault();
            var cancelledPersonBooking = db.Venue_Booking_Person.Where(p => p.Venue_Booking_Seq.Equals(a.booking_seq) && p.Person_ID == User.Identity.Name).FirstOrDefault();

            //change booking status to cancelled
            if (cancelledBooking.Booking_Type_Seq == 2)
            {
                cancelledPersonBooking.Attendee_Status = "Cancelled";
            }
            else
            {
                cancelledPersonBooking.Attendee_Status = "Cancelled";
                cancelledBooking.Booking_Status        = "Cancelled";
            }

            //capture the cancellation
            db.Entry(cancelledBooking).State       = EntityState.Modified;
            db.Entry(cancelledPersonBooking).State = EntityState.Modified;

            //record action
            global.addAudit("Bookings", "Bookings: Cancelled Booking", "Delete", User.Identity.Name);

            db.SaveChanges();

            //set notification information
            TempData["Message"]    = "Booking successfuly cancelled";
            TempData["classStyle"] = "success";

            //go back to the main view bookings folder
            var site = Url.Action("ViewBookings", "Booking");

            return(Content(site));
        }
예제 #8
0
 public ActionResult Edit(string id, MemberEditVM viewModel)
 {
     TempData["Show"] = false;
     if (ModelState.IsValid)
     {
         Registered_Person rp = db.Registered_Person.Find(id);
         rp.Person_ID       = id;
         rp.Person_Name     = viewModel.person_name;
         rp.Person_Surname  = viewModel.person_surname;
         rp.Person_Email    = viewModel.person_email;
         rp.Person_Type     = "Student";
         db.Entry(rp).State = EntityState.Modified;
         db.SaveChanges();
         TempData["Msg"]   = "Member updated successfully.";
         TempData["Show"]  = true;
         TempData["color"] = "alert-success";
     }
     return(RedirectToAction("Index"));
 }
예제 #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
            {
            }
        }
예제 #10
0
        public ActionResult UpdateFile(UpdateFileModel model)
        {
            if (ModelState.IsValid)
            {
                //get instance of the file to be updated
                var updatedfile = db.Document_Repository.Where(f => f.Document_Seq.Equals(model.Document_Seq)).FirstOrDefault();
                //update the entries details
                updatedfile.Document_Name    = model.Document_Name;
                updatedfile.Description      = model.Description;
                updatedfile.Category_ID      = model.Category_ID;
                updatedfile.Document_Type_ID = model.Document_Type_ID;
                //check if a new file has been uploaded
                if (model.uploadFile != null)
                {
                    //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"]   = "danger";
                        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
                    {
                        System.IO.File.Delete(updatedfile.Directory_Path);
                        model.uploadFile.SaveAs(path);
                        updatedfile.Directory_Path = path;
                    }
                }
                db.Entry(updatedfile).State = EntityState.Modified;
                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    = updatedfile.Document_Seq;
                ac.Session_ID      = sessionLog.Session_ID;

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

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

                TempData["Message"]    = "File successfuly updated";
                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(model));
            }
        }
예제 #11
0
        public ActionResult Edit(int id, RoleEditModel roleEdit)
        {
            int  Count  = 0;
            bool create = true;
            bool read   = true;
            bool update = true;
            bool delete = true;

            try
            {
                ViewBag.ErrorMsg = "";
                var query = (from q in db.Roles
                             where q.Role_Name.ToLower() == roleEdit.role.Role_Name.ToLower()
                             select q);
                if (query.Count() >= 2)
                {
                    ViewBag.ErrorMsg = "The role name exists, please provide a different role name";
                    RoleEditModel roleModel = new RoleEditModel();
                    roleModel.role = db.Roles.Find(id);
                    if (roleModel.role == null)
                    {
                        return(HttpNotFound());
                    }
                    roleModel.actionList = db.Role_Action.Where(
                        i => i.Role_ID == id).ToList();
                    return(View(roleModel));
                }
                Role r = db.Roles.Find(id);
                r.Role_Name       = roleEdit.role.Role_Name;
                db.Entry(r).State = EntityState.Modified;

                foreach (var o in roleEdit.actionList)
                {
                    Role_Action ra = db.Role_Action.Find(o.RoleAction_ID);
                    ra.Create_Ind      = o.Create_Ind;
                    ra.Read_Ind        = o.Read_Ind;
                    ra.Update_Ind      = o.Update_Ind;
                    ra.Delete_Ind      = o.Delete_Ind;
                    db.Entry(ra).State = EntityState.Modified;

                    if (create == false)
                    {
                        Count++;
                    }
                    read = o.Read_Ind;
                    if (read == false)
                    {
                        Count++;
                    }
                    update = o.Update_Ind;
                    if (update == false)
                    {
                        Count++;
                    }
                    delete = o.Delete_Ind;
                    if (delete == false)
                    {
                        Count++;
                    }
                    if (Count == (roleEdit.actionList.Count() * 4))
                    {
                        ViewBag.Error = "Role must be assigned at least 1 action";
                        RoleEditModel roleModel = new RoleEditModel();
                        roleModel.role = db.Roles.Find(id);
                        if (roleModel.role == null)
                        {
                            return(HttpNotFound());
                        }
                        roleModel.actionList = db.Role_Action.Where(
                            i => i.Role_ID == id).ToList();
                        return(View(roleModel));
                    }
                }
                db.SaveChanges();
                return(RedirectToAction("Index", "Role"));
            }
            catch
            {
                RoleEditModel roleModel = new RoleEditModel();
                roleModel.role = db.Roles.Find(id);
                if (roleModel.role == null)
                {
                    return(HttpNotFound());
                }
                roleModel.actionList = db.Role_Action.Where(
                    i => i.Role_ID == id).ToList();
                return(View(roleModel));
            }
        }