Esempio n. 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);
        }
Esempio n. 2
0
        public ActionResult ResignConfirmed(int id)
        {
            TSTEmployee tSTEmployee = db.TSTEmployees.Find(id);

            if (tSTEmployee.DepartmentID == 6)
            {
                if (tSTEmployee.EmpStatusID == 2)
                {
                    tSTEmployee.EmpStatusID = 6;

                    tSTEmployee.EmpEndDate = DateTime.Now;
                }
                else if (tSTEmployee.EmpStatusID == 6)
                {
                    tSTEmployee.EmpStatusID   = 2;
                    tSTEmployee.EmpDateOfHire = DateTime.Now;
                }
            }
            else
            {
                if (tSTEmployee.EmpStatusID == 1)
                {
                    tSTEmployee.EmpStatusID = 5;

                    tSTEmployee.EmpEndDate = DateTime.Now;
                }
            }
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Esempio n. 3
0
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TSTEmployee tSTEmployee = db.TSTEmployees.Find(id);


            if (tSTEmployee == null)
            {
                return(HttpNotFound());
            }
            ViewBag.State = new SelectList(GetProvincesList());
            if (tSTEmployee.DepartmentID == 6)
            {
                ViewBag.EmpStatusID = new SelectList(db.TSTEmployeeStatuses.Where(s => s.EmpStatusID.Equals(2) || s.EmpStatusID.Equals(4) || s.EmpStatusID.Equals(6)), "EmpStatusID", "EmpStatusName", tSTEmployee.EmpStatusID);
            }
            else
            {
                ViewBag.EmpStatusID  = new SelectList(db.TSTEmployeeStatuses.Where(s => s.EmpStatusID.Equals(1) || s.EmpStatusID.Equals(3) || s.EmpStatusID.Equals(5)), "EmpStatusID", "EmpStatusName", tSTEmployee.EmpStatusID);
                ViewBag.DepartmentID = new SelectList(db.TSTDepartments.Where(d => d.DepartmentID != tSTEmployee.DepartmentID).Where(d => d.DepartmentID != 6), "DepartmentID", "DepartmentName", tSTEmployee.DepartmentID);
            }
            return(View(tSTEmployee));
        }
Esempio n. 4
0
        public JsonResult ChangePhoto(int Id, string img)
        {
            TSTEmployee emp           = db.TSTEmployees.Single(x => x.EmpID == Id);
            var         currentUserId = User.Identity.GetUserId();

            //create user employee relationship by matching user id to user id of employee

            TSTEmployee e = db.TSTEmployees.FirstOrDefault(x => x.EmpUserID == currentUserId);

            if (img != null)
            {
                string imageName = img.Substring(img.LastIndexOf('/') + 1);
                emp.EmpPhoto = imageName;

                db.SaveChanges();
                var data = new
                {
                    Id            = emp.EmpID,
                    Photo         = emp.EmpPhoto,
                    ModelUserID   = emp.EmpUserID,
                    CurrentUserID = e.EmpUserID
                };
                return(Json(data, JsonRequestBehavior.AllowGet));
            }


            return(null);
        }
Esempio n. 5
0
        public ActionResult DeleteConfirmed(int id)
        {
            TSTEmployee tSTEmployee = db.TSTEmployees.Find(id);

            db.TSTEmployees.Remove(tSTEmployee);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        //prework for Notes
        //Get Emokoyee(tech - For Notes, for Create - It is the submittedByID)
        //In order for this to work, we must have tied the identity
        //AspNetUsers Table to the TSTEmployee table. (Means each TSTEmployee is
        //represented in the AspNetUsers Tabel via the email address. )
        //This will not work if you are still using [email protected] UNLESS you created
        //an employee with taht email address.

        public TSTEmployee GetCurrentEmoloyee()
        {
            var         currentUser = User.Identity.Name;                           //AspNetUser UserName (email)
            TSTEmployee e           = db.TSTEmployees
                                      .FirstOrDefault(x => x.Email == currentUser); //compare the TSTEmployee address

            //and only return the TSTEmoloyee that synchs with the AspNetUser Name
            return(e);
        }
Esempio n. 7
0
        public TSTEmployee GetCurrentEmployee()
        {
            var currentUserId = User.Identity.GetUserId();

            //create user employee relationship by matching user id to user id of employee

            TSTEmployee e = db.TSTEmployees.FirstOrDefault(x => x.EmpUserID == currentUserId);

            return(e);
        }
Esempio n. 8
0
 public ActionResult Edit([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.Entry(tSTEmployee).State = EntityState.Modified;
         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));
 }
 public ActionResult Edit([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.Entry(tSTEmployee).State = EntityState.Modified;
         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));
 }
        // GET: TSTEmployees/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TSTEmployee tSTEmployee = db.TSTEmployees.Find(id);

            if (tSTEmployee == null)
            {
                return(HttpNotFound());
            }
            return(View(tSTEmployee));
        }
        //AddTechNote()
        /// <summary>
        /// Notation informations:
        /// This is the method that is going to be called by jquery/Ajax from the edie
        /// view to add the note on the fly and persist it to the (Tech)Notes Table
        /// it will post the NEW note to the view in the notes section BEFORE submitting the
        /// form.
        /// </summary>

        public JsonResult AddTechNote(int ticketId, string note)
        {
            //get the ticket that was passed in to the method and retrieve the associated
            //record.
            TSTTicket ticket = db.TSTTickets.Single(x => x.TicketID == ticketId);

            //get the current logged on employee so taht we can fulfill the
            //TechID field for the TSTTechNote
            TSTEmployee tech = GetCurrentEmoloyee();

            //Make the note
            //make sure the TSTEmployee is not null
            if (tech != null)
            {
                //Create the TSTNote object
                TSTTicketNote newNote = new TSTTicketNote()
                {
                    //object initialization syntax
                    //property = (is assiged the value) of
                    //hard coded / passed in data
                    TicketID     = ticketId,   //passed into the method
                    Notation     = note,       //passed into the method
                    EmpID        = tech.EmpID, //derived
                    NotationDate = DateTime.Now
                };
                //Persist the note at the data structure
                //save changes
                db.TSTTicketNotes.Add(newNote);
                db.SaveChanges();
                //----the note is created - exists at the data structure
                //now we need to send it back to the view, so we can display it in the
                //edit view
                //This NEVER hits the wevserver, jQuery has not idea what the TSTNote
                //objec is.  We send over datat that can be parsed by jQuery.

                var data = new
                {
                    //otf (on the fly variable) = newNote.Property
                    TechNotes = newNote.Notation,
                    Tech      = newNote.TSTEmployee.fname,
                    Date      = string.Format("{0:g}", newNote.NotationDate)
                                //because this doesn't hit the webserver, we format it here
                };
                //send notation infor to the browser for jQuery to parse
                return(Json(data, JsonRequestBehavior.AllowGet));
            }//end the if

            return(null);//no note if employee is null.
        }//ends the AddNewNote()
        // GET: TSTEmployees/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TSTEmployee tSTEmployee = db.TSTEmployees.Find(id);

            if (tSTEmployee == null)
            {
                return(HttpNotFound());
            }
            ViewBag.DeptID = new SelectList(db.TSTDepartments, "DeptID", "DeptName", tSTEmployee.DeptID);
            return(View(tSTEmployee));
        }
Esempio n. 13
0
        public ActionResult Create()
        {
            //Order has to be submitted by a manager, and a shop worker is assigned the order.

            //ViewBag.SubmittedByID = new SelectList(db.TSTEmployees.Where(a => a.DeptID == 2), "EmployeeID", "FName");
            TSTEmployee e = db.TSTEmployees.Where(x => x.Email == User.Identity.Name).Single();

            ViewBag.TechID = new SelectList(db.TSTEmployees.Where(d => d.DeptID == 3), "EmployeeID", "FName");

            ViewBag.PriorityID     = new SelectList(db.TSTOrderPriorities, "PriorityID", "Name");
            ViewBag.TicketStatusID = new SelectList(db.TSTOrderStatuses, "TicketStatusID", "Name");
            ViewBag.OrderTypeID    = new SelectList(db.TSTOrderTypes, "OrderTypeID", "Name");
            return(View("AssignedOrders"));
            //RedirectToAction("AssignedOrders");
        }
Esempio n. 14
0
        /// <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 lost it to the
        /// notes section BEFORE submitting the form.
        /// </summary>
        /// <returns>JsonResult</returns>
        ///
        public JsonResult AddTechNote(int ticketId, string note)
        {
            //get the ticket associated with the record ID (passed to method)
            TSTOrder ticket = db.TSTOrders.Single(x => x.TicketID == ticketId);
            //get the current logged on employee as the technician.  This
            //code ONLY Works because we have our TSTEmployees table tied
            //to our identity Users table.  TstEmployee.Email == ASPUser.Email,
            //TstEmployee.Email == User.Identity.Name,
            //UserId == TstEmployee UserID
            TSTEmployee tech = db.TSTEmployees.Single(x => x.Email == User.Identity.Name);

            //make sure the TSTEmployee object is not null.
            if (tech != null)
            {
                //create the TSTNote object
                //using initialization syntax assign values
                TSTShopNote newNote = new TSTShopNote()
                {
                    TicketID     = ticketId,        //passed to the method
                    TechID       = tech.EmployeeID, //derived above, need the Employee ID
                    NotationDate = DateTime.Now,    //hard-coded
                    Notation     = note             //passed to the method
                };
                //Send the note to EF
                db.TSTShopNotes.Add(newNote);
                //Save the note to the datastructure
                db.SaveChanges();
                //--------------The Note is added to the DB-----------------
                //--------------Send to the browser for parsing and display
                //This never hits the web server, jQuery has NO IDEA what
                // a TSTNOTE is.  We send over "data" to be parsed by jQuery.

                var data = new
                {
                    //otf (on the fly) variable = newNote.Property
                    TechNotes = newNote.Notation,
                    Tech      = newNote.TSTEmployee.FName + " " + newNote.TSTEmployee.LName,

                    Date = string.Format("{0:g}", newNote.NotationDate)
                };
                //send the note stuff back to the browser to be parsed
                return(Json(data, JsonRequestBehavior.AllowGet));
            }



            return(null);
        }
Esempio n. 15
0
        public ActionResult DeleteConfirmed(int id)
        {
            TSTTicket tSTTicket     = db.TSTTickets.Find(id);
            var       currentUserId = User.Identity.GetUserId();

            //create user employee relationship by matching user id to user id of employee

            TSTEmployee e = db.TSTEmployees.FirstOrDefault(x => x.EmpUserID == currentUserId);

            if (e.DepartmentID == 1 || e.DepartmentID == 3)
            {
                switch (tSTTicket.TicketStatusID)
                {
                case 1:
                    //assign ticket
                    tSTTicket.TicketStatusID = 2;
                    tSTTicket.TSTEmployee1   = e;
                    break;

                case 2:
                    tSTTicket.TicketStatusID = 3;
                    //move it to in progress status
                    break;

                case 3:
                    tSTTicket.TicketStatusID = 4;
                    //resolve the ticket
                    tSTTicket.TicketResolved = DateTime.Now;
                    tSTTicket.PriorityID     = 1;
                    break;

                case 4:
                    tSTTicket.TicketStatusID = 1;
                    //reopen ticket un asssign from tech. Put in very high priority
                    tSTTicket.TechID     = null;
                    tSTTicket.PriorityID = 4;
                    break;

                default:
                    break;
                }
            }



            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Edit([Bind(Include = "ID,Fname,Lname,DOB,Address1,Address2,City,State,Zip,Email,Phone,HireDate,SeparationDate,JobTitle,IsActive,Image,Note,UserID,DeptID,StatusID")]
                                 TSTEmployee tSTEmployee, HttpPostedFileBase empImage)
        {
            if (ModelState.IsValid)
            {
                #region FileUpload
                //empImage
                //default the value of the imageName to
                //string imageName = tSTEmployee.Image;

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

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

                    // 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));
                        tSTEmployee.Image = imageName;
                    }
                    else
                    {
                        // if nothing else change image back to no photo
                        imageName = "No-Image.svg.png";
                    }
                }
                #endregion

                db.Entry(tSTEmployee).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.DeptID   = new SelectList(db.TSTDepartments, "ID", "Name", tSTEmployee.DeptID);
            ViewBag.StatusID = new SelectList(db.TSTEmployeeStatuses, "ID", "Name", tSTEmployee.StatusID);
            return(View(tSTEmployee));
        }
Esempio n. 17
0
        // GET: TSTEmployees/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TSTEmployee tSTEmployee = db.TSTEmployees.Find(id);
            var         tSTTickets  = db.TSTTickets.Include(t => t.TSTEmployee).Include(t => t.TSTEmployee1).Include(t => t.TSTPriorite).Include(t => t.TSTTicketStatus);

            ViewBag.PassMyTickets = tSTTickets.ToList();
            ViewBag.PassImg       = tSTEmployee.EmpPhoto;

            if (tSTEmployee == null)
            {
                return(HttpNotFound());
            }
            return(View(tSTEmployee));
        }
        /// <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);
        }
Esempio n. 19
0
        public ActionResult DeleteConfirmed(int id)
        {
            TSTEmployee tSTEmployee = db.TSTEmployees.Find(id);

            #region soft delete

            if (tSTEmployee.EmpStatusID == 4)
            {
                tSTEmployee.EmpStatusID = 1;
            }
            else
            {
                tSTEmployee.EmpStatusID = 4;
            }

            #endregion
            #region Autogenerate separation date on delete(and toggle back if they are already deleted)
            if (tSTEmployee.EmpStatusID != 4)
            {
                tSTEmployee.SeparationDate = null;
                tSTEmployee.HireDate       = DateTime.Now;
                //db.Entry(tSTEmployee).State = EntityState.Modified;
                //db.SaveChanges();
                //return RedirectToAction("Index");
            }
            else
            {
                tSTEmployee.SeparationDate = DateTime.Now;
                //db.Entry(tSTEmployee).State = EntityState.Modified;
                //db.SaveChanges();
                //return RedirectToAction("Index");
            }


            #endregion
            //commented out hard delete
            //db.TSTEmployees.Remove(tSTEmployee);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "ID,SubmitedByID,TechID,CreatedDate,ResolutionDate,Description,StatusID,PriorityID,Subject")] TSTTicket tSTTicket)
        {
            if (ModelState.IsValid)
            {
                TSTEmployee e = db.TSTEmployees.FirstOrDefault(x => x.Email == User.Identity.Name);
                tSTTicket.SubmitedByID = e.ID;
                tSTTicket.CreatedDate  = DateTime.Now;
                tSTTicket.StatusID     = 1;
                tSTTicket.PriorityID   = 3;


                db.TSTTickets.Add(tSTTicket);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SubmitedByID = new SelectList(db.TSTEmployees, "ID", "Fname", tSTTicket.SubmitedByID);
            ViewBag.TechID       = new SelectList(db.TSTEmployees, "ID", "Fname", tSTTicket.TechID);
            ViewBag.PriorityID   = new SelectList(db.TSTTicketPriorities, "ID", "Name", tSTTicket.PriorityID);
            ViewBag.StatusID     = new SelectList(db.TSTTicketStatuses, "ID", "Name", tSTTicket.StatusID);
            return(View(tSTTicket));
        }
Esempio n. 21
0
        public ActionResult Create([Bind(Include = "TicketID,TicketSubject,TicketDescription,SubmittedByID,TechID,TicketSubmitted,TicketResolved,TicketStatusID,Image,PriorityID")] TSTTicket tSTTicket)
        {
            if (ModelState.IsValid)
            {
                TSTEmployee e = GetCurrentEmployee();
                tSTTicket.SubmittedByID   = e.EmpID;
                tSTTicket.TicketSubmitted = DateTime.Now;
                tSTTicket.TicketStatusID  = 1;
                tSTTicket.Image           = "Noimage.png";
                tSTTicket.PriorityID      = 1;

                db.TSTTickets.Add(tSTTicket);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SubmittedByID  = new SelectList(db.TSTEmployees, "EmpID", "EmpFname", tSTTicket.SubmittedByID);
            ViewBag.TechID         = new SelectList(db.TSTEmployees, "EmpID", "EmpFname", tSTTicket.TechID);
            ViewBag.PriorityID     = new SelectList(db.TSTPriorites, "PriorityID", "PriorityName", tSTTicket.PriorityID);
            ViewBag.TicketStatusID = new SelectList(db.TSTTicketStatuses, "TicketStatusID", "TicketStatusName", tSTTicket.TicketStatusID);
            return(View(tSTTicket));
        }
        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));
        }
Esempio n. 23
0
        public ActionResult Create(
            [Bind(Include = "EmployeeID,FName,LName,DeptID,EmpStatusID,HireDate,SeparationDate,Salary,Address1,Address2,City,State,Zip,Phone,Email,EmpPhoto,JobTitle,UserID")]
            TSTEmployee tSTEmployee, HttpPostedFileBase prodImage,
            string[] selectedRoles)//must match the name value of the input - casing does not matter
        {
            if (ModelState.IsValid)
            {
                #region Add UserID to Employee Object
                //Similar code can be found in the UserAdmin Create()
                //HTTPPost Controller/Action

                //Create a UserManager object
                var userManager = System.Web.HttpContext.Current.GetOwinContext().
                                  GetUserManager <ApplicationUserManager>();

                //Create an application User and Assign the UserName and the email properties
                var newUser = new ApplicationUser()
                {
                    UserName = tSTEmployee.Email,
                    Email    = tSTEmployee.Email
                };
                //-----------------------------------------------------
                //Create the User object with the default password
                userManager.Create(newUser, "P@ssw0rd");
                //Examples: El3ph@nt  Y3ahR!ght
                //dynamically
                //Fname + "Z1234$"
                //This actually sets the default password
                //You could go to the identityConfig.cs and configure email
                //to send the password to them after registry.  Do not forget
                //to set up email in the web.config if you do this
                //(if you are not going to use the identity.config)

                //add the user to a role - as long as the role value is not null
                if (selectedRoles != null)
                {
                    userManager.AddToRoles(newUser.Id, selectedRoles);
                }
                //if not then add to the default role user/customer/ect.
                else
                {
                    userManager.AddToRole(newUser.Id, "User");
                }
                //assign the tSTEmployee.UserID property and send the data to the data structure
                tSTEmployee.UserID = newUser.Id;
                #endregion

                #region file uploade in create view for employee

                string imageName = "noimage.jpg";
                if (prodImage != null)
                {
                    imageName = prodImage.FileName;

                    string ext = imageName.Substring(
                        imageName.LastIndexOf('.'));

                    string[] goodExts = new string[]
                    {
                        ".gif", ".jpg", ".bmp", ".jpeg", ".png"
                    };

                    if (goodExts.Contains(ext))
                    {
                        imageName = Guid.NewGuid() + ext;

                        prodImage.SaveAs(Server.MapPath("~/Content/img/employeephotos/" + imageName));
                    }
                    else
                    {
                        imageName = "noimage.jpg";
                    }
                }
                tSTEmployee.EmpPhoto = imageName;
                #endregion

                #region AutoGenerate Date of Create

                tSTEmployee.HireDate = DateTime.Now;


                #endregion
                #region Autogenerate Employee Status

                tSTEmployee.EmpStatusID = 1;

                //tSTEmployee.TSTEmployeeStatus.EmployeeStatusID = 1;

                #endregion
                #region Autogenerate Salary Based on Department chosen

                if (tSTEmployee.DeptID == 1)
                {
                    tSTEmployee.Salary = 55000m;
                }
                else if (tSTEmployee.DeptID == 2)
                {
                    tSTEmployee.Salary = 65000m;
                }
                else if (tSTEmployee.DeptID == 3)
                {
                    tSTEmployee.Salary = 30000m;
                }
                else
                {
                    tSTEmployee.Salary = 100000m;
                }

                #endregion

                #region Autogenerate Position based on department

                if (tSTEmployee.DeptID == 1)
                {
                    tSTEmployee.JobTitle = "Shop Worker";
                }
                else if (tSTEmployee.DeptID == 2)
                {
                    tSTEmployee.JobTitle = "Shop Manager";
                }
                else if (tSTEmployee.DeptID == 3)
                {
                    tSTEmployee.JobTitle = "HR Representative";
                }
                else
                {
                    tSTEmployee.JobTitle = "Owner";
                }

                #endregion


                //#region Disable any selection of an inactive department
                //tSTEmployee.TSTDepartment.IsActive = true;
                //#endregion//this one does not seem to work (return later

                db.TSTEmployees.Add(tSTEmployee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            #region Identity Roles Cheackbox List
            //Add a viewbag item so that we can display the Identity Roles to be selected when a
            //new user is created.

            //part of the createing a User Object when creating the Employee
            //is to retrieve a list of roles from Identity.

            //OWIN - Open Web Interface for .Net
            var RoleManager = HttpContext.GetOwinContext().Get <ApplicationRoleManager>();

            //create  VIEWBAG OBJECT TO PASS TO THE VIEW TO BE CONSUMED.
            ViewBag.RoleID = new SelectList(RoleManager.Roles.ToList().OrderBy(r => r.Name), "Name", "Name");



            #endregion
            ViewBag.DeptID      = new SelectList(db.TSTDepartments, "DepartmentID", "Name", tSTEmployee.DeptID);
            ViewBag.EmpStatusID = new SelectList(db.TSTEmployeeStatuses, "EmployeeStatusID", "EmployeeStatusName", tSTEmployee.EmpStatusID);
            return(View(tSTEmployee));
        }
Esempio n. 24
0
        public ActionResult Edit([Bind(Include = "EmployeeID,FName,LName,DeptID,EmpStatusID,HireDate,SeparationDate,Salary,Address1,Address2,City,State,Zip,Phone,Email,EmpPhoto,JobTitle,UserID")]
                                 TSTEmployee tSTEmployee, HttpPostedFileBase prodImage)
        {
            if (ModelState.IsValid)
            {
                #region File Upload Edit Processing


                if (prodImage != null)
                {
                    string imageName = prodImage.FileName;
                    string ext       = imageName.Substring(
                        imageName.LastIndexOf('.'));

                    string[] goodExts = new String[]
                    {
                        ".gif", ".jpg", ".jpeg", ".bmp", ".png"
                    };
                    if (goodExts.Contains(ext))
                    {
                        imageName = Guid.NewGuid() + ext;

                        prodImage.SaveAs(Server.MapPath("~/Content/img/employeephotos/"
                                                        + imageName));

                        tSTEmployee.EmpPhoto = imageName;
                    }
                    //else
                    //{
                    //    //reassign imagename variable to be the ORIGINAL VALUE
                    //    //db-->Products Table where OUR Object.ID
                    //    //is the same as the EXISTING Product.ID
                    //    //Getting only the Image Name value
                    //    //the .Single() tells .NET that only 1
                    //    //item is being returned - By default
                    //    //linq returns an IQueryable
                    //    imageName = db.TSTEmployees.Where(wgp => wgp.EmployeeID
                    //    == tSTEmployee.EmployeeID).Select(wgp => wgp.EmpPhoto).Single();


                    //    //we could send them back to the create view
                    //    //and populate the create and use a viewbag
                    //    //message as an error

                    //    //ViewBag.Err = "Please supply a valid file type.";
                    //    ////then only display this if the viewbag item is NOT null
                    //    ////in the view.
                    //    //return View(tSTEmployee);
                    //}
                }


                #endregion
                db.Entry(tSTEmployee).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            ViewBag.DeptID      = new SelectList(db.TSTDepartments, "DepartmentID", "Name", tSTEmployee.DeptID);
            ViewBag.EmpStatusID = new SelectList(db.TSTEmployeeStatuses, "EmployeeStatusID", "EmployeeStatusName", tSTEmployee.EmpStatusID);
            return(View(tSTEmployee));
        }
Esempio n. 25
0
        public ActionResult Edit([Bind(Include = "EmpID,EmpFname,EmpLname,DepartmentID,EmpStatusID,EmpAddress1,EmpAddress2,EmpCity,EmpState,EmpPhoto,EmpUserID,EmpDateOfBirth,EmpDateOfHire,EmpEndDate,EmpPhone,EmpEmail,EmpNotes")] TSTEmployee tSTEmployee, string img, string grabPic)
        {
            ModelState.Clear();
            if (ModelState.IsValid)
            {
                // string imageName = grabPic;
                ////get images for delete
                ////check if file is empty
                //if (img != null)
                //{
                //    imageName = img.Substring(img.LastIndexOf('/') + 1);

                //}
                //tSTEmployee.EmpPhoto = imageName;


                //create the user manager

                //send back to identitiy default pass

                //add the user to selected roles
                var userManager = System.Web.HttpContext.Current.GetOwinContext()
                                  .GetUserManager <ApplicationUserManager>();
                //grab the user's user id, then the role, then remove them from the role, based on department
                var newUser  = userManager.FindByEmail(tSTEmployee.EmpEmail);
                var userRole = userManager.GetRoles(newUser.Id.ToString());

                //manages role and status assignment
                switch (tSTEmployee.DepartmentID)
                {
                case 1:    //admin
                    tSTEmployee.EmpStatusID = 1;
                    userManager.RemoveFromRole(newUser.Id.ToString(), userRole[0]);
                    userManager.AddToRole(newUser.Id.ToString(), "Admin");
                    break;

                case 3:    //teacher
                    tSTEmployee.EmpStatusID = 1;
                    userManager.RemoveFromRole(newUser.Id.ToString(), userRole[0]);
                    userManager.AddToRole(newUser.Id.ToString(), "Tech");
                    break;

                case 4:    //HR
                    tSTEmployee.EmpStatusID = 1;
                    userManager.RemoveFromRole(newUser.Id.ToString(), userRole[0]);
                    userManager.AddToRole(newUser.Id.ToString(), "Teacher");
                    break;

                case 5:
                    tSTEmployee.EmpStatusID = 1;
                    userManager.RemoveFromRole(newUser.Id.ToString(), userRole[0]);
                    userManager.AddToRole(newUser.Id.ToString(), "HR");
                    break;

                default:    //student
                    tSTEmployee.EmpStatusID = 2;
                    userManager.RemoveFromRole(newUser.Id.ToString(), userRole[0]);
                    userManager.AddToRole(newUser.Id.ToString(), "Student");
                    break;
                }


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

                return(RedirectToAction("Index"));
            }
            if (tSTEmployee.DepartmentID == 6)
            {
                ViewBag.EmpStatusID = new SelectList(db.TSTEmployeeStatuses.Where(s => s.EmpStatusID.Equals(2) || s.EmpStatusID.Equals(4) || s.EmpStatusID.Equals(6)), "EmpStatusID", "EmpStatusName", tSTEmployee.EmpStatusID);
            }
            else
            {
                ViewBag.EmpStatusID  = new SelectList(db.TSTEmployeeStatuses.Where(s => s.EmpStatusID.Equals(1) || s.EmpStatusID.Equals(3) || s.EmpStatusID.Equals(5)), "EmpStatusID", "EmpStatusName", tSTEmployee.EmpStatusID);
                ViewBag.DepartmentID = new SelectList(db.TSTDepartments.Where(d => d.DepartmentID != tSTEmployee.DepartmentID).Where(d => d.DepartmentID != 6), "DepartmentID", "DepartmentName", tSTEmployee.DepartmentID);
            }
            ViewBag.State = new SelectList(GetProvincesList());
            return(View(tSTEmployee));
        }
Esempio n. 26
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));
        }
        public ActionResult Edit([Bind(Include = "EmpID,fname,lname,address1,address2,City,State,zip,phone1,phone2,Email,DeptID,Image,DOB,HireDate,SeparationDate,IsActive,JobTitle,Notes,UserID")]
                                 TSTEmployee tSTEmployee, HttpPostedFileBase empPhoto)
        {
            if (ModelState.IsValid)
            {
                #region FileUPload
                //prework, find a no photo avalable image
                //we will use this image as a default instead of Leaving it null

                //the image already exists with the record

                //see if the user uploaded an image
                if (empPhoto != null)
                {
                    //get the file name
                    string imageName = empPhoto.FileName;

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

                    //check the extension to ensure it is appropriate
                    //create an array of VALID extensions and compare
                    //the current value of ext
                    string[] goodExts = new string[]
                    { ".png", ".jpg", ".jpeg", ".gif" };

                    //if it its valid
                    if (goodExts.Contains(ext))
                    {
                        //rename the file - Guid (Global Unique Identifier
                        //and concatonate teh extenstion
                        imageName = Guid.NewGuid() + ext;

                        //save the FILE to the webserver
                        empPhoto.SaveAs(Server.MapPath(
                                            "~/Content/images/Employee/" + imageName));

                        //send the text value of the imagename to the db
                        tSTEmployee.Image = imageName;
                    }
                }
                //the hiddenfield will continue to hold the original image and
                //care for anything that shuld bvwe in the else


                #endregion



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

                if (tSTEmployee.IsActive)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(RedirectToAction("InactiveEmployees"));
                }
            }

            ViewBag.DeptID = new SelectList(db.TSTDepartments, "DeptID", "DeptName", tSTEmployee.DeptID);
            return(View(tSTEmployee));
        }
        public ActionResult Create([Bind(Include = "EmpID,fname,lname,address1,address2,City,State,zip,phone1,phone2,Email,DeptID,Image,DOB,HireDate,SeparationDate,IsActive,JobTitle,Notes,UserID")]
                                   TSTEmployee tSTEmployee, string[] selectedRoles,
                                   HttpPostedFileBase empPhoto)

        {
            if (ModelState.IsValid)
            {
                #region Create Identity User when creating an Employee
                //This same type of code can be found in the UsersAdmin Create()
                //HttpPost action for teh controller

                //Create a new UserManager object
                var userManager = System.Web.HttpContext.Current.
                                  GetOwinContext().GetUserManager <ApplicationUserManager>();


                //create the new application user and assign value to the Username
                //and email properties
                var newUser = new ApplicationUser()
                {
                    UserName = tSTEmployee.Email,
                    Email    = tSTEmployee.Email
                };

                //use the usermanager to create the userName and password combo
                userManager.Create(newUser, "P@ssw0rd");
                //other options
                //EL3ph@nt, Y3aR!ght, FirstName+x12345$
                //This actually sets the password for the user
                //you could go to the Identity.Config and configure
                //to email the user their password.  If you do that, do not forget
                //to setup email in the web.config or in the Identity.config
                //There is NO need to do both

                //add the user to teh selected role(s)
                if (selectedRoles != null)
                {
                    userManager.AddToRoles(newUser.Id, selectedRoles);
                }
                else
                {
                    //no selection to the cbl
                    userManager.AddToRole(newUser.Id, "User");
                }

                //now that we ahve an Identity User, assign the valie to
                //the Employee.UserID property
                tSTEmployee.UserID = newUser.Id;

                #endregion

                //prework, find a no photo avalable image
                //we will use this image as a default instead of Leaving it null

                //default the value of the variable
                //imageName to our no photo name value
                string imageName = "noPhoto.jpg";

                //see if the user uploaded an image
                if (empPhoto != null)
                {
                    //get the file name
                    imageName = empPhoto.FileName;

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

                    //check the extension to ensure it is appropriate
                    //create an array of VALID extensions and compare
                    //the current value of ext
                    string[] goodExts = new string[]
                    { ".png", ".jpg", ".jpeg", ".gif" };

                    //if it its valid
                    if (goodExts.Contains(ext))
                    {
                        //rename the file - Guid (Global Unique Identifier
                        //and concatonate teh extenstion
                        imageName = Guid.NewGuid() + ext;

                        //save the FILE to the webserver
                        empPhoto.SaveAs(Server.MapPath(
                                            "~/Content/images/Employee/" + imageName));
                    }
                    else
                    {
                        //BAD EXTENSION
                        //assign the imageName to [ourDefaultName]
                        imageName = "NoPhoto.jpg";
                    }
                }
                //no matter what
                //send the text value of the imagename to the db
                tSTEmployee.Image = imageName;



                db.TSTEmployees.Add(tSTEmployee);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            var RoleManager = HttpContext.GetOwinContext().Get <ApplicationRoleManager>();

            //create a viewbag object ot pass to the view to be consumed and populate our checkboxlist (we
            //will need this in the [Http] post as well.)
            ViewBag.RoleId =
                new SelectList(RoleManager.Roles.ToList().OrderBy(r => r.Name), "Name", "Name");

            ViewBag.DeptID = new SelectList(db.TSTDepartments, "DeptID", "DeptName", tSTEmployee.DeptID);
            return(View(tSTEmployee));
        }
Esempio n. 29
0
        public ActionResult Create([Bind(Include = "TicketID,TroubleDescription,Picture,OrderTypeID,Quantity")]
                                   TSTOrder tSTOrder, HttpPostedFileBase prodImage)
        {
            TSTEmployee e = db.TSTEmployees.Where(x => x.Email == User.Identity.Name).Single();

            tSTOrder.TicketStatusID = 2;
            //priority is set to medium
            tSTOrder.PriorityID = 2;
            if (ModelState.IsValid)
            {
                //tech ID is null
                tSTOrder.TechID = null;
                #region File Upload Create

                string imageName = "NoImage.gif";

                if (prodImage != null)
                {
                    imageName = prodImage.FileName;

                    string ext = imageName.Substring(
                        imageName.LastIndexOf('.')).ToLower();

                    string[] goodExts = new string[]
                    {
                        ".gif", ".jpg", ".png", ".bmp", ".jpeg"
                    };
                    if (goodExts.Contains(ext))
                    {
                        imageName = Guid.NewGuid() + ext;

                        //save it to the webserver
                        //(website/Content/Images/ProductImages)
                        prodImage.SaveAs(Server.MapPath(
                                             "~/Content/img/OrderImages/"
                                             + imageName));
                    }
                    else
                    {
                        imageName = "NoImage.gif";
                    }
                }
                tSTOrder.Picture = imageName;

                #endregion
                //#region Automatic Order Status Assignment
                //#endregion
                #region Automatic date assignment
                tSTOrder.StartDate = DateTime.Now;//needs to be parsed i believe
                #endregion
                #region Auto-assign the subject of the order based on OrderTypeID

                if (tSTOrder.OrderTypeID == 1)
                {
                    tSTOrder.Subject = "Silk Screen";
                }
                else
                {
                    tSTOrder.Subject = "Embroidery";
                }


                #endregion

                //Assign the employee id
                tSTOrder.SubmittedByID = e.EmployeeID;

                db.TSTOrders.Add(tSTOrder);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SubmittedByID  = e.EmployeeID;
            ViewBag.TechID         = new SelectList(db.TSTOrderPriorities, "TechID", "Name", tSTOrder.TechID);
            ViewBag.PriorityID     = new SelectList(db.TSTOrderPriorities, "PriorityID", "Name", tSTOrder.PriorityID);
            ViewBag.TicketStatusID = new SelectList(db.TSTOrderStatuses, "TicketStatusID", "Name", tSTOrder.TicketStatusID);
            ViewBag.OrderTypeID    = new SelectList(db.TSTOrderTypes, "OrderTypeID", "Name", tSTOrder.OrderTypeID);
            return(View(tSTOrder));
        }