private void OnCreateClick(object sender, RoutedEventArgs e)
        {
            employee newEmployee = new employee()
            {
                name              = nameTextBox.Text,
                address           = addressTextBox.Text,
                email             = emailTextBox.Text,
                phone             = phoneTextBox.Text,
                employment_status = employmentStatusComboBox.Text,
                shift             = shiftComboBox.Text,
                favorite_color    = favoriteColorTextBox.Text,
            };

            if (startDatePicker.SelectedDate.HasValue)
            {
                newEmployee.start_date = startDatePicker.SelectedDate.Value;
            }

            newEmployee.position_id = (from pos in dbContext.positions
                                       where pos.name == positionComboBox.Text
                                       select pos.id).First();

            newEmployee.department_id = (from dept in dbContext.departments
                                         where dept.name == departmentComboBox.Text
                                         select dept.id).First();

            string mgrString = managerComboBox.Text;

            string[] parts = mgrString.Split('-');
            if (parts.Length > 1)
            {
                newEmployee.manager_id = Int32.Parse(parts[1].Trim());
            }

            dbContext.employees.Add(newEmployee);
            dbContext.SaveChanges();

            log logEntry = new log()
            {
                time        = System.DateTime.Now,
                change_type = "Create",
                employee_id = newEmployee.id,
                new_value   = newEmployee.name
            };

            dbContext.logs.Add(logEntry);
            dbContext.SaveChanges();
            MessageBox.Show("Employee " + newEmployee.name + " added!");

            HomePage homePage = new HomePage();

            this.NavigationService.Navigate(homePage);
        }
        public ActionResult Homepage(int contestantId, int VoteSessionId)
        {
            var usr = Session["Username"];
            var pw  = Session["Password"];

            //to make sure you have signed in.
            if (usr?.ToString() == null || pw?.ToString() == null)
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "Please you have to sign in first!!";
                return(Redirect("Login"));
            }
            if (db.EligibleMembers.Where(dbl => dbl.email.ToLower() == usr.ToString().ToLower() && dbl.password == pw.ToString()).Count() == 0)
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "Please enter a valid email amd password combination!!";
                return(Redirect("Login"));
            }
            //vote once
            foreach (var voterecord in db.voteLogs)
            {
                if (voterecord.VotingSessionId == VoteSessionId && voterecord.EligibleMember.email.ToLower() == usr.ToString().ToLower())
                {
                    TempData["MessageType"] = "danger";
                    TempData["Message"]     = "You can only vote once!!";
                    return(Redirect("Homepage"));
                }
            }
            var     person = db.EligibleMembers.Where(dbl => dbl.email.ToLower() == usr.ToString().ToLower() && dbl.password == pw.ToString()).First();
            voteLog c      = new voteLog
            {
                datetime        = DateTime.Now,
                contestantId    = contestantId,
                VotingSessionId = VoteSessionId,
                memberId        = person.Id
            };
            voteLog cc = db.voteLogs.Add(c);

            db.SaveChanges();
            ViewBag.memberId        = person.Id;
            TempData["MessageType"] = "success";
            TempData["Message"]     = "Your vote was successful casted!!";
            return(View());
        }
        private void OnDeleteClick(object sender, RoutedEventArgs e)
        {
            MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Delete Confirmation", System.Windows.MessageBoxButton.YesNo);

            if (messageBoxResult == MessageBoxResult.Yes)
            {
                dbContext.employees.Remove(currentEmployee);
                dbContext.SaveChanges();
            }

            EmployeeList employeeList = new EmployeeList();

            this.NavigationService.Navigate(employeeList);
        }
예제 #4
0
        protected void Button4_Click1(object sender, EventArgs e)
        {
            string s = docu_upload(FileUpload3);

            if (s.Equals("-1"))
            {
                Label8.Text = "Image Could not be Uploaded,,,,,,,,";
            }
            else
            {
                tbl_hsc hsc = new tbl_hsc();
                hsc.hsc_institute  = TextBox3.Text;
                hsc.hsc_percentage = float.Parse(TextBox4.Text);
                hsc.hsc_doc        = s;
                hsc.hsc_fk_ap_id   = Convert.ToInt32(Session["u_id"].ToString());
                db.tbl_hsc.AddObject(hsc);
                db.SaveChanges();
                Response.Write("<script>alert('data successfully inserted');</script>");
            }
        }//end method
예제 #5
0
 public void check()
 {
     foreach (var item in db.Contestants)
     {
         if (DateTime.Now > item.VotingSession.closeDateTime)
         {
             item.status = false;
         }
         else
         {
             item.status = true;
         }
     }
     foreach (var item in db.VotingSessions)
     {
         if (DateTime.Now > item.closeDateTime)
         {
             item.status = false;
         }
         else
         {
             item.status = true;
         }
         if (DateTime.Now < item.startDateTime)
         {
             item.moment = moment.UpComing.ToString();//"Up Coming";
         }
         else if (DateTime.Now >= item.startDateTime && DateTime.Now <= item.closeDateTime)
         {
             item.moment = moment.InProgress.ToString();//"In Progress";
         }
         else if (DateTime.Now > item.closeDateTime)
         {
             item.moment = moment.Completed.ToString();//"Completed";
         }
     }
     db.SaveChanges();
 }
예제 #6
0
        public ActionResult RegisterMember(EligibleMember model)
        {
            #region personal picture validation
            if (Request.Files[0].ContentLength == 0 || Request.Files[0].FileName == "")
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "Please input your postal image!!";
                return(View(model));
            }
            if (Request.Files[0].ContentLength >= 20000000)
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "File too large!!";
                return(View(model));
            }
            if (Request.Files[0].ContentType.Substring(0, 5) != "image")
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "Invalid file type!!";
                return(View(model));
            }
            #endregion

            #region member data validation
            foreach (var item in db.EligibleMembers)
            {
                if (model.email.ToLower() == item.email.ToLower())
                {
                    TempData["MessageType"] = "danger";
                    TempData["Message"]     = "The email has already been used!!";
                    return(View(model));
                }
                if (model.phone_number == item.phone_number)
                {
                    TempData["MessageType"] = "danger";
                    TempData["Message"]     = "The phone number has already been used!!";
                    return(View(model));
                }
                if (model.membership_number.ToLower() == item.membership_number.ToLower())
                {
                    TempData["MessageType"] = "danger";
                    TempData["Message"]     = "Someone already has that membership number!!";
                    return(View(model));
                }
            }
            if (model.phone_number.Trim().Length < 7 || model.phone_number.Trim().Length > 15)
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "Please input a valid phone number!!";
                return(View(model));
            }
            if (model.password != model.confirmPassword)
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "Your password and confirm password information does not tally!!";
                return(View(model));
            }
            if (model.password.Length < 8)
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "Your password should be at least 8 characters!!";
                return(View(model));
            }
            if (model.password.Length > 15)
            {
                TempData["MessageType"] = "danger";
                TempData["Message"]     = "Your password should be at most 15 characters!!";
                return(View(model));
            }
            #endregion

            #region save member data
            EligibleMember c = new EligibleMember
            {
                fullname          = model.fullname,
                email             = model.email,
                phone_number      = model.phone_number,
                membership_number = model.membership_number,
                password          = model.password,
            };

            var f = Request.Files[0];
            c.ImageName     = f.FileName;
            c.ImageFileType = f.ContentType;

            using (var reader = new BinaryReader(f.InputStream))
            {
                c.ImageContent = reader.ReadBytes(f.ContentLength);
            }
            EligibleMember cc = db.EligibleMembers.Add(c);
            db.SaveChanges();
            TempData["MessageType"] = "success";
            TempData["Message"]     = "Your Registration was successful!!";
            return(View());

            #endregion
        }
        public void OnUpdateChangesClick(object sender, RoutedEventArgs e)
        {
            List <log> entries = new List <log>();

            if (!currentEmployee.name.Equals(nameTextBox.Text))
            {
                entries.Add(logEntry("Name", currentEmployee.name, nameTextBox.Text));
                currentEmployee.name = nameTextBox.Text;
            }
            if (!currentEmployee.address.Equals(addressTextBox.Text))
            {
                entries.Add(logEntry("Address", currentEmployee.address, addressTextBox.Text));
                currentEmployee.address = addressTextBox.Text;
            }
            if (!currentEmployee.email.Equals(emailTextBox.Text))
            {
                entries.Add(logEntry("Email", currentEmployee.email, emailTextBox.Text));
                currentEmployee.email = emailTextBox.Text;
            }
            if (!currentEmployee.phone.Equals(phoneTextBox.Text))
            {
                entries.Add(logEntry("Phone", currentEmployee.phone, phoneTextBox.Text));
                currentEmployee.phone = phoneTextBox.Text;
            }
            if (!currentEmployee.employment_status.Equals(employmentStatusComboBox.Text))
            {
                entries.Add(logEntry("Employment Status", currentEmployee.employment_status, employmentStatusComboBox.Text));
                currentEmployee.employment_status = employmentStatusComboBox.Text;
            }
            if (!currentEmployee.shift.Equals(shiftComboBox.Text))
            {
                entries.Add(logEntry("Shift", currentEmployee.shift, shiftComboBox.Text));
                currentEmployee.shift = shiftComboBox.Text;
            }
            if (!currentEmployee.favorite_color.Equals(favoriteColorTextBox.Text))
            {
                entries.Add(logEntry("Favorite Color", currentEmployee.email, favoriteColorTextBox.Text));
                currentEmployee.favorite_color = favoriteColorTextBox.Text;
            }
            if (startDatePicker.SelectedDate.HasValue)
            {
                if (!currentEmployee.start_date.Equals(startDatePicker.SelectedDate.Value))
                {
                    entries.Add(logEntry("Start Date", currentEmployee.start_date, startDatePicker.SelectedDate.Value));
                }
                currentEmployee.start_date = startDatePicker.SelectedDate.Value;
            }
            if (endDatePicker.SelectedDate.HasValue)
            {
                if (!currentEmployee.start_date.Equals(endDatePicker.SelectedDate.Value))
                {
                    entries.Add(logEntry("End Date", currentEmployee.end_date, endDatePicker.SelectedDate.Value));
                }
                currentEmployee.end_date = endDatePicker.SelectedDate.Value;
            }
            if (!currentEmployee.position.name.Equals(positionComboBox.Text))
            {
                entries.Add(logEntry("Position", currentEmployee.position.name, positionComboBox.Text));
                currentEmployee.position_id = (from posi in dbContext.positions
                                               where posi.name == positionComboBox.Text
                                               select posi.id).First();
            }
            if (!currentEmployee.department.name.Equals(departmentComboBox.Text))
            {
                entries.Add(logEntry("Department", currentEmployee.department.name, departmentComboBox.Text));
                currentEmployee.department_id = (from dept in dbContext.departments
                                                 where dept.name == departmentComboBox.Text
                                                 select dept.id).First();
            }

            string mgrString = managerComboBox.Text;

            string[] parts = mgrString.Split('-');
            if (parts.Length > 1)
            {
                int newManagerId = Int32.Parse(parts[1].Trim());
                if (currentEmployee.manager_id != newManagerId)
                {
                    entries.Add(logEntry("Manager", oldManagerName, parts[0].Trim()));
                    currentEmployee.manager_id = newManagerId;
                }
            }

            int len = dbContext.employees.Local.Count();
            int pos = len;

            for (int i = 0; i < len; i++)
            {
                if (currentEmployee.id == dbContext.employees.Local[i].id)
                {
                    pos = i;
                    break;
                }
            }

            dbContext.employees.Local.Insert(pos, currentEmployee);
            dbContext.SaveChanges();

            addChangeLog(entries);

            EmployeeDetails employeeDetails = new EmployeeDetails(currentEmployee.id);

            this.NavigationService.Navigate(employeeDetails);
        }