Ejemplo n.º 1
0
        protected void submitPD(object sender, EventArgs e)
        {
            request PDRequest = new request();
            decimal totalHours;

            try
            {
                using (var PDreqcontext = new PCTEntities())
                {
                    PDRequest.dept_id        = Convert.ToInt32(deptDropDownList.SelectedValue);
                    PDRequest.requestType_id = Convert.ToInt32(TypeRequest_dropdown.SelectedValue);
                    PDRequest.userAccount_id = Convert.ToInt32(current_user);
                    PDRequest.created        = requestStarted;
                    PDRequest.submitted      = DateTime.Now;
                    //startDate is datetime instead of date.
                    DateTime fromDate = Convert.ToDateTime(datepickerSingle.Value);
                    DateTime toDate   = Convert.ToDateTime(datepickerSingle.Value);
                    PDRequest.startDate = fromDate.Date;
                    PDRequest.endDate   = toDate.Date;
                    var      start  = PDstartTime.Text; //fix
                    var      end    = PDendTime.Text;
                    DateTime start2 = Convert.ToDateTime(start);
                    DateTime end2   = Convert.ToDateTime(end);

                    PDRequest.startTime  = TimeSpan.Parse(start);
                    PDRequest.endTime    = TimeSpan.Parse(end);
                    totalHours           = Convert.ToDecimal((end2 - start2).TotalHours);//switch the to and from
                    PDRequest.totalHours = Convert.ToDecimal(totalHours);
                    PDRequest.status     = "Pending";
                    PDRequest.comments   = commentbox.Text.Trim();
                    //CREATE GOOGLE CALENDAR EVENT
                    CreateCalEvent(PDRequest);
                    //inserts the google calendar event id
                    PDRequest.eventID = insertedEventId;
                    //update userAccount forcasted and current available hours
                    PDreqcontext.requests.Add(PDRequest);
                    PDreqcontext.SaveChanges();
                }

                //Update used V hours and  P hours
                using (var useracct2 = new PCTEntities())
                {
                    var subLunch = (Convert.ToDecimal(LunchPD.Text) / 60);
                    var user2    = (from u in useracct2.userAccounts
                                    where u.ID.ToString() == current_user
                                    select u).First();
                    if (TypeRequest_dropdown.SelectedValue == "0")//Personal Type
                    {
                        if (!LunchCheckBoxPD.Checked)
                        {
                            user2.usedPHours = Convert.ToDecimal(totalHours + user2.usedPHours);
                        }
                        else
                        {
                            user2.usedPHours = Convert.ToDecimal((totalHours + user2.usedPHours) - subLunch);
                        }
                    }
                    else //Type is Vacation
                    {
                        if (!LunchCheckBoxPD.Checked)
                        {
                            user2.usedVHours = Convert.ToDecimal(totalHours + user2.usedVHours);
                        }
                        else
                        {
                            user2.usedVHours = Convert.ToDecimal((totalHours + user2.usedVHours) - subLunch);
                        }
                    }

                    useracct2.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            //email to supervisor and user
            emailDetails(PDRequest);
            //redirect to beginning
            Response.Redirect("RequestOff.aspx");
        }
Ejemplo n.º 2
0
        protected void SubmitBtn_Click(object sender, EventArgs e)
        {
            userAccount userEnt = new userAccount();

            PasswordRFV.Enabled    = true;
            confirmPassRFV.Enabled = true;
            try
            {
                //if user is creating a new user
                if (UserMode.Text == "NewUser")
                {
                    //
                    using (var PCTModel = new PCTEntities())
                    {
                        //post
                        int fullday;
                        int lunchBreak;
                        using (var context = new PCTEntities())
                        {
                            userEnt.first_name  = fname_txt.Text;
                            userEnt.last_name   = lname_txt.Text;
                            userEnt.email       = username_txt.Text;
                            userEnt.dateCreated = DateTime.Now;
                            userEnt.createdBy   = current_user;
                            userEnt.emp_id      = Convert.ToInt32(EmployeeDropDown.SelectedValue);
                            userEnt.userRole_id = Convert.ToInt32(RoleDropDownList.SelectedValue);
                            if (empStat_dropdownlist.SelectedItem.ToString() == "Full-Time")
                            {
                                fullday    = 8;
                                lunchBreak = 60;
                            }
                            else if (empStat_dropdownlist.SelectedItem.ToString() == "Part-Time")
                            {
                                fullday    = 4;
                                lunchBreak = 15;
                            }
                            else
                            {
                                fullday    = 0;
                                lunchBreak = 0;
                            }
                            userEnt.fullDayHours = fullday;
                            userEnt.lunch        = lunchBreak;
                            //BAD PRACTICE
                            userEnt.hashedPassword = NewPassword.Value.ToString();
                            //account status, and user role
                            int accountStat = Convert.ToInt16(acct_dropdownlist.SelectedValue);
                            userEnt.accountStatus = Convert.ToBoolean(accountStat);


                            //------------------create a hashed password-----------------------
                            //string password = NewPassword.Value.ToString();
                            // // Run the functions on the code,
                            // string hashed = Crypto.Hash(password, "MD5");
                            // string sha256 = Crypto.SHA256(password);
                            // string sha1 = Crypto.SHA1(password);

                            //string salt = Crypto.GenerateSalt();

                            // hashedPassword = Crypto.HashPassword(password);

                            // // First parameter is the previously hashed string using a Salt
                            // verify = Crypto.VerifyHashedPassword("{hash_password_here}", password);
                            //}

                            context.userAccounts.Add(userEnt);
                            context.SaveChanges();
                        }
                    }
                }
                if (UserMode.Text == "EditUser")
                {
                    PasswordRFV.Enabled    = false;
                    confirmPassRFV.Enabled = false;

                    using (var editUserSub = new PCTEntities())
                    {
                        var User = (from ua in editUserSub.userAccounts
                                    where ua.ID.ToString() == UserDropDown.SelectedValue
                                    select ua).First();

                        User.first_name  = fname_txt.Text;
                        User.last_name   = lname_txt.Text;
                        User.email       = username_txt.Text;
                        User.lastUpdated = DateTime.Now;
                        User.userRole_id = Convert.ToInt32(RoleDropDownList.SelectedValue);
                        int accountStat = Convert.ToInt16(acct_dropdownlist.SelectedValue);
                        User.accountStatus = Convert.ToBoolean(accountStat);
                        //BAD PRACTICE
                        bool np = string.IsNullOrEmpty(NewPassword.Value.ToString());
                        bool cp = string.IsNullOrEmpty(confirmPass_txt.Text);
                        if (np == false && cp == false)
                        {
                            User.hashedPassword = NewPassword.Value.ToString();
                        }
                        //account status, and user role
                        int accountStatus2 = Convert.ToInt16(acct_dropdownlist.SelectedValue);
                        userEnt.accountStatus = Convert.ToBoolean(accountStatus2);


                        //------------------create a hashed password-----------------------
                        //string password = NewPassword.Value.ToString();
                        // // Run the functions on the code,
                        // string hashed = Crypto.Hash(password, "MD5");
                        // string sha256 = Crypto.SHA256(password);
                        // string sha1 = Crypto.SHA1(password);

                        //string salt = Crypto.GenerateSalt();

                        // hashedPassword = Crypto.HashPassword(password);

                        // // First parameter is the previously hashed string using a Salt
                        // verify = Crypto.VerifyHashedPassword("{hash_password_here}", password);
                        //}

                        editUserSub.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 3
0
        //when a user clicks submit for a full day request off
        protected void submitFD(object sender, EventArgs e)
        {
            request FDRequest = new request();
            decimal totalHours;

            try
            {
                using (var FDreqcontext = new PCTEntities())
                {
                    FDRequest.dept_id        = Convert.ToInt32(deptDropDownList.SelectedValue);
                    FDRequest.requestType_id = Convert.ToInt32(TypeRequest_dropdown.SelectedValue);
                    FDRequest.userAccount_id = Convert.ToInt32(current_user);
                    FDRequest.created        = requestStarted;
                    FDRequest.submitted      = DateTime.Now;
                    //startDate is datetime instead of date.
                    DateTime fromDate = Convert.ToDateTime(from.Value);
                    DateTime toDate   = Convert.ToDateTime(to.Value);
                    //format date
                    //var fromDate2 = fromDate.Date;
                    //var toDate2 = toDate.Date;
                    int dateDiff = Convert.ToInt32(((toDate - fromDate).TotalDays) + 1);//switch the to and from
                    totalHours = ((dateDiff * (Convert.ToDecimal(fullDayHours.Text) - Convert.ToDecimal(Convert.ToDecimal(lunch.Text) / 60))));


                    FDRequest.startDate  = fromDate;
                    FDRequest.endDate    = toDate;
                    FDRequest.totalHours = Convert.ToDecimal(totalHours);
                    //time
                    string newFromDate = fromDate.ToString("hh:mm");
                    string newToDate   = toDate.ToString("hh:mm");

                    FDRequest.startTime = TimeSpan.Parse(newFromDate);
                    FDRequest.endTime   = TimeSpan.Parse(newToDate);

                    FDRequest.status   = "Pending";
                    FDRequest.comments = commentBox2.Text.Trim();
                    //CREATE GOOGLE CALENDAR EVENT
                    CreateCalEvent(FDRequest);
                    //inserts the google calendar event id
                    FDRequest.eventID = insertedEventId;
                    //update userAccount forcasted and current available hours

                    FDreqcontext.requests.Add(FDRequest);
                    FDreqcontext.SaveChanges();
                }
                var subLunchFd = (Convert.ToDecimal(lunch.Text) / 60);
                //Update used V hours and  P hours
                using (var useracct = new PCTEntities())
                {
                    var user = (from u in useracct.userAccounts
                                where u.ID.ToString() == current_user
                                select u).First();
                    if (TypeRequest_dropdown.SelectedValue == "0")//Personal Type
                    {
                        user.usedPHours = Convert.ToDecimal((totalHours + user.usedPHours) - subLunchFd);
                    }
                    else //Type is Vacation
                    {
                        user.usedVHours = Convert.ToDecimal((totalHours + user.usedVHours) - subLunchFd);
                    }
                    useracct.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            //email to supervisor and user
            emailDetails(FDRequest);
            //redirect to beginning
            Response.Redirect("RequestOff.aspx");
        }