示例#1
0
        public JsonResult AddTechNote(int ticketId, string note)
        {
            //get the ticket that was passed in and pull the associated record

            //get the current logged on employee (the tech working on the ticket)

            //this only works cause of stuff we made happen yeah


            TSTTicket ticket = db.TSTTickets.Single(x => x.TicketID == ticketId);

            TSTEmployee tech = GetCurrentEmployee();

            if (tech != null)
            {
                TSTTechNote newNote = new TSTTechNote()
                {
                    TicketID     = ticketId,
                    TechID       = tech.EmpID,
                    NotationDate = DateTime.Now,
                    Notation     = note
                };
                db.TSTTechNotes.Add(newNote);
                db.SaveChanges();
                var data = new
                {
                    TechNotes = newNote.Notation,
                    Tech      = newNote.TSTEmployee.GetFullName,
                    Date      = string.Format("{0:g}", newNote.NotationDate)
                };
                return(Json(data, JsonRequestBehavior.AllowGet));
            }

            return(null);
        }
        public ActionResult Create([Bind(Include = "ID,Name,Description,IsActive")] TSTDepartment tSTDepartment)
        {
            if (ModelState.IsValid)
            {
                db.TSTDepartments.Add(tSTDepartment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tSTDepartment));
        }
        public ActionResult Create([Bind(Include = "TicketStatusID,TicketStatusName,TicketStatusDescription")] TSTTicketStatus tSTTicketStatus)
        {
            if (ModelState.IsValid)
            {
                db.TSTTicketStatuses.Add(tSTTicketStatus);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tSTTicketStatus));
        }
示例#4
0
        public ActionResult Create([Bind(Include = "ID,Name,Description")] TSTTicketPriority tSTTicketPriority)
        {
            if (ModelState.IsValid)
            {
                db.TSTTicketPriorities.Add(tSTTicketPriority);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tSTTicketPriority));
        }
示例#5
0
        public ActionResult Create([Bind(Include = "PriorityID,PriorityName,PriorityDescription")] TSTPriorite tSTPriorite)
        {
            if (ModelState.IsValid)
            {
                db.TSTPriorites.Add(tSTPriorite);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tSTPriorite));
        }
示例#6
0
        public ActionResult Create([Bind(Include = "ID,Name,Description")] tstEmployeeStatu tstEmployeeStatu)
        {
            if (ModelState.IsValid)
            {
                db.tstEmployeeStatus.Add(tstEmployeeStatu);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(tstEmployeeStatu));
        }
        public ActionResult Create([Bind(Include = "ID,TechID,TicketID,Notation,NotationDate")] tstTechNote tstTechNote)
        {
            if (ModelState.IsValid)
            {
                db.tstTechNotes.Add(tstTechNote);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TechID   = new SelectList(db.tstEmployees, "ID", "Name", tstTechNote.TechID);
            ViewBag.TicketID = new SelectList(db.tstTickets, "ID", "TroubleDescription", tstTechNote.TicketID);
            return(View(tstTechNote));
        }
示例#8
0
        public ActionResult Create([Bind(Include = "EmployeeID,UserID,EmpStatusID,EmpImage,FName,LName,DeptID,JobTitle,DateOfBirth,StreetAddress,Address2,City,State,Zip,Email,CellPhone,DateOfHire,DateOfSeparation,EmpNotes")] TSTEmployee tSTEmployee)
        {
            if (ModelState.IsValid)
            {
                db.TSTEmployees.Add(tSTEmployee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DeptID      = new SelectList(db.TSTDepartments, "DeptID", "DeptName", tSTEmployee.DeptID);
            ViewBag.EmpStatusID = new SelectList(db.TSTEmpStatuses, "EmpStatusID", "EmpStatusName", tSTEmployee.EmpStatusID);
            return(View(tSTEmployee));
        }
示例#9
0
        public ActionResult Create([Bind(Include = "ID,Name,Lname,Hiredate,UserID,StatusID,Jobtitle,Adress,Adress2,City,State,Zip,Email,Phone,DepID,ImmageURL,Notes,Dateofbirth,separationDate")] tstEmployee tstEmployee)
        {
            if (ModelState.IsValid)
            {
                db.tstEmployees.Add(tstEmployee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DepID    = new SelectList(db.tstDepartments, "ID", "Name", tstEmployee.DepID);
            ViewBag.StatusID = new SelectList(db.tstEmployeeStatus, "ID", "Name", tstEmployee.StatusID);
            return(View(tstEmployee));
        }
        public ActionResult Create([Bind(Include = "EmpID,EmpFname,EmpLname,DeptID,EmpStatID,EmpAdd1,EmpAdd2,Area,Town_City,PostCode,PhoneNbr,UserID,DOB,DateOfHire,DateOfSeparation,Email,Image,Notes")] TSTEmployee tSTEmployee)
        {
            if (ModelState.IsValid)
            {
                db.TSTEmployees.Add(tSTEmployee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.DeptID    = new SelectList(db.TSTDepartments, "DeptID", "DeptName", tSTEmployee.DeptID);
            ViewBag.EmpStatID = new SelectList(db.TSTEmpStatus, "EmpStatID", "EmpStatName", tSTEmployee.EmpStatID);
            return(View(tSTEmployee));
        }
示例#11
0
        public ActionResult Create([Bind(Include = "MailID,MailSubject,MailMessage,SentByID,DateSent,PriorityID,RecipientID,IsActive")] TSTMail tSTMail)
        {
            if (ModelState.IsValid)
            {
                db.TSTMails.Add(tSTMail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SentByID    = new SelectList(db.TSTEmployees, "EmployeeID", "UserID", tSTMail.SentByID);
            ViewBag.RecipientID = new SelectList(db.TSTEmployees, "EmployeeID", "UserID", tSTMail.RecipientID);
            ViewBag.PriorityID  = new SelectList(db.TSTPriorities, "PriorityID", "PriorityName", tSTMail.PriorityID);
            return(View(tSTMail));
        }
示例#12
0
        public ActionResult Create([Bind(Include = "TicketID,TicketSubject,TicketDescription,TicketImage,SubmittedByID,DateSubmitted,TicketStatusID,TechID,PriorityID,DateResolved")] TSTTicket tSTTicket)
        {
            if (ModelState.IsValid)
            {
                db.TSTTickets.Add(tSTTicket);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.TechID         = new SelectList(db.TSTEmployees, "EmployeeID", "UserID", tSTTicket.TechID);
            ViewBag.SubmittedByID  = new SelectList(db.TSTEmployees, "EmployeeID", "UserID", tSTTicket.SubmittedByID);
            ViewBag.PriorityID     = new SelectList(db.TSTPriorities, "PriorityID", "PriorityName", tSTTicket.PriorityID);
            ViewBag.TicketStatusID = new SelectList(db.TSTTicketStatuses, "TicketStatusID", "TicketStatusName", tSTTicket.TicketStatusID);
            return(View(tSTTicket));
        }
示例#13
0
        public ActionResult Create([Bind(Include = "ID,SubmitbyID,TechID,CreatedDate,ResoloutionDate,TroubleDescription,Screenshot,StatusID,PriorityID,Subject")] tstTicket tstTicket)
        {
            if (ModelState.IsValid)
            {
                db.tstTickets.Add(tstTicket);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SubmitbyID = new SelectList(db.tstEmployees, "ID", "Name", tstTicket.SubmitbyID);
            ViewBag.TechID     = new SelectList(db.tstEmployees, "ID", "Name", tstTicket.TechID);
            ViewBag.PriorityID = new SelectList(db.tstTicketPriorties, "ID", "Name", tstTicket.PriorityID);
            ViewBag.StatusID   = new SelectList(db.tstTicketStatus, "ID", "Name", tstTicket.StatusID);
            return(View(tstTicket));
        }
        /// <summary>
        /// Notation Information:
        /// This is the method that is going to be called by jQuery/Ajax from the edit view to add the note on the fly AND post it to the notes section BEFORE submitting the form.
        ///
        /// AJAX - Asynchronous JavaScript and XML (makes calles without reloading page)
        ///
        /// </summary>

        public JsonResult AddTechNote(int ticketID, string note)
        {
            // get the ticketID passed in to the method and get the associated record
            TSTTicket ticket = db.TSTTickets.Single(x => x.ID == ticketID);
            // Get the current logged on employee ( who is working the ticket)
            TSTEmployee tech = db.TSTEmployees.Single(x => x.Email == User.Identity.Name); // this code requires all employees are associated to a user ID in Identity

            // This code only works because we associated the TSTEmployee table to the Identity AspNetUser Table


            // make sure the tech is not null
            if (tech != null)
            {
                // create TstNote object and submit
                TSTTechNote newNote = new TSTTechNote()
                {
                    // Property is assigned a value
                    TicketID    = ticketID,     // passed thru the method
                    TechID      = tech.ID,      // derived from employee above
                    TimeCreated = DateTime.Now, // hard coded
                    Notes       = note          // passed in thru the method
                };
                // add note record to the table
                db.TSTTechNotes.Add(newNote);
                db.SaveChanges();

                //return data to the view to be displayed. This NEVER hits the webserver, so jQuery has NO IDEA what a TSTTechNote.
                // We send over data that can be parsed by jQuery.
                var data = new
                {
                    // On the Fly Variable = newNote.Property,
                    TechNotes = newNote.Notes,
                    Tech      = newNote.TSTEmployee.Fname,
                    Date      = string.Format("{0:g}", newNote.TimeCreated)
                                // never hits webserver so formatting is done here
                };
                // send note information back to the browser for jQuery to parse
                return(Json(data, JsonRequestBehavior.AllowGet));
            }
            return(null);
        }
        public ActionResult Create([Bind(Include = "ID,Fname,Lname,DOB,Address1,Address2,City,State,Zip,Email,Phone,HireDate,SeparationDate,JobTitle,IsActive,Image,Note,UserID,DeptID,StatusID")]
                                   TSTEmployee tSTEmployee, string[] selectedRoles, HttpPostedFileBase empImage) // HttpPostedFileBase *View
        {
            if (ModelState.IsValid)
            {
                #region Create Identity User when Creating an employee
                // similar code can be found in the UserAdmin Create()
                // HttpPost action for the controller

                // create new UserManager object
                var userManager = System.Web.HttpContext.Current.GetOwinContext().GetUserManager <ApplicationUserManager>();
                // create new application user - assign the default Username and password
                var newUser = new ApplicationUser()
                {
                    UserName = tSTEmployee.Email,
                    Email    = tSTEmployee.Email
                };
                // usermanager creates the username and password combination
                userManager.Create(newUser, "P@ssw0rd");
                // This actually sets the password for the user. you could go to the Identity.config and configure to email the user their password to them. If you do that, do not forget to setup email in the web.config
                // or in the Identity.config ( no need to do both)


                // add the user to the selected role(s) - make sure we care for a null selection
                if (selectedRoles != null)
                {
                    userManager.AddToRoles(newUser.Id, selectedRoles);
                }
                else
                {
                    // no selection
                    userManager.AddToRole(newUser.Id, "User");
                }

                // assign the tSTEmployee.UserId property and send to the data structure

                tSTEmployee.UserID = newUser.Id;


                #endregion

                #region FileUpload
                //empImage
                //default the value of the imageName to
                string imageName = "No-Image.svg.png";

                if (empImage != null)
                {
                    //get the filename
                    imageName = empImage.FileName;

                    //use the filename to get the extension
                    string ext = imageName.Substring(imageName.LastIndexOf('.'));

                    // conversation about malicious code
                    // white list
                    string[] goodExts = new string[] { ".png", ".jpg", ".jpeg", ".gif" };

                    if (!goodExts.Contains(ext))
                    {
                        // rename the file using a guid and add the ext
                        imageName = Guid.NewGuid() + ext;

                        // save to the webserver
                        empImage.SaveAs(Server.MapPath("~/Images/EmployeeImages/" + imageName));
                    }
                    else
                    {
                        // if nothing else change image back to no photo
                        imageName = "No-Image.svg.png";
                    }
                    // no matter what, add the image value to the employee object
                    tSTEmployee.Image = imageName;
                }
                #endregion
                db.TSTEmployees.Add(tSTEmployee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            var RoleManager = HttpContext.GetOwinContext().Get <ApplicationRoleManager>();
            // create Viewbag object to pass to the view to be consumed and populate the CBL. (we will need this in the post as well)
            ViewBag.RoleId = new SelectList(RoleManager.Roles.ToList().OrderBy(r => r.Name), "Name", "Name");


            ViewBag.DeptID   = new SelectList(db.TSTDepartments, "ID", "Name", tSTEmployee.DeptID);
            ViewBag.StatusID = new SelectList(db.TSTEmployeeStatuses, "ID", "Name", tSTEmployee.StatusID);
            return(View(tSTEmployee));
        }
示例#16
0
        public ActionResult Create([Bind(Include = "EmpID,EmpFname,EmpLname,DepartmentID,EmpStatusID,EmpAddress1,EmpAddress2,EmpCity,EmpState,EmpPhoto,EmpUserID,EmpDateOfBirth,EmpDateOfHire,EmpEndDate,EmpEmail,EmpPhone,EmpNotes")] TSTEmployee tSTEmployee)
        {
            ModelState.Clear();
            //programmatically generate email from first letter of first name + [email protected]
            string email = tSTEmployee.EmpFname.ToLower().First() + tSTEmployee.EmpLname.ToLower() + tSTEmployee.EmpPhone.Substring((tSTEmployee.EmpPhone.Length - 4)) + "@greendale.com";

            tSTEmployee.EmpEmail = email;
            //ModelState.Add()
            //ModelState.
            //set hire date
            tSTEmployee.EmpDateOfHire = DateTime.Now;


            //set status ID
            //if student enrolled status if employee active status
            if (tSTEmployee.DepartmentID == 6)
            {
                tSTEmployee.EmpStatusID = 2;
            }
            else
            {
                tSTEmployee.EmpStatusID = 1;
            }
            //set default no image

            tSTEmployee.EmpPhoto = "noPhoto.png";


            if (ModelState.IsValid)
            {
                try
                {
                    //similar code can be found in the users admin controller

                    //create the user manager
                    var userManager = System.Web.HttpContext.Current.GetOwinContext()
                                      .GetUserManager <ApplicationUserManager>();
                    //create new app user and assign username email
                    var newUser = new ApplicationUser()
                    {
                        //object initialization syntax
                        UserName = tSTEmployee.EmpEmail,
                        Email    = tSTEmployee.EmpEmail
                    };
                    //send back to identitiy default pass
                    userManager.Create(newUser, "P@ssw0rd");
                    //add the user to selected roles

                    switch (tSTEmployee.DepartmentID)
                    {
                    case 1:    //admin
                        userManager.AddToRole(newUser.Id, "Admin");
                        break;

                    case 3:    //teacher
                        userManager.AddToRole(newUser.Id, "Tech");
                        break;

                    case 4:    //HR
                        userManager.AddToRole(newUser.Id, "Teacher");
                        break;

                    case 5:
                        userManager.AddToRole(newUser.Id, "HR");
                        break;

                    default:    //student
                        userManager.AddToRole(newUser.Id, "Student");
                        break;
                    }
                    //default to a role if none provided

                    //assign employee identity id
                    tSTEmployee.EmpUserID = newUser.Id;


                    db.TSTEmployees.Add(tSTEmployee);
                    db.SaveChanges();
                    return(RedirectToAction("Details", new { id = tSTEmployee.EmpID }));
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("modelstate?", e);
                }
            }



            var RoleManager = HttpContext.GetOwinContext().Get <ApplicationRoleManager>();

            ViewBag.State = new SelectList(GetProvincesList());

            ViewBag.RoleID = new SelectList(RoleManager.Roles.ToList(), "Name", "Name");

            ViewBag.DepartmentID = new SelectList(db.TSTDepartments, "DepartmentID", "DepartmentName", tSTEmployee.DepartmentID);
            return(View(tSTEmployee));
        }