예제 #1
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            foreach (IValidator i in this.Validators)
            {
                i.Validate();
            }

            if (IsValid)
            {
                MyUserDataGrid my = new MyUserDataGrid();

                my.Id          = user.Id;
                my.Email       = user.Email;
                my.Password    = userPassword.Text;
                my.Birthday    = DateTime.Parse(userBirthay.Value);
                my.Name        = userName.Text;
                my.Surname     = userSurname.Text;
                my.FathersName = userFathersName.Text;
                my.Phone       = userPhone.Text;
                my.City        = userCity.SelectedValue;
                my.Roles       = "Employer";


                MyCompanyDetail detail = new MyCompanyDetail();
                detail.Id            = company.Id;
                detail.Name          = companyName.Text;
                detail.WebSite       = companyWebSite.Text;
                detail.TypeOfCompany = (companyType.Items.IndexOf(companyType.SelectedItem) == 0) ? 0 : 1;

                List <string> categories = userCategories.Items.OfType <ListItem>().Where(i => i.Selected).Select(i1 => i1.Text).ToList();

                for (int i = 0; i < categories.Count; i++)
                {
                    if (i == categories.Count - 1)
                    {
                        my.Categories += categories[i];
                    }
                    else
                    {
                        my.Categories += (categories[i] + ", ");
                    }
                }


                companyBase.Save(detail);

                my.CompanyDetails = userManager.GetLastCompId();

                userBase.Save(my);

                Response.Redirect("~/Employer.aspx");
            }
        }
예제 #2
0
        public object GetPropertyValue(MyUserDataGrid my, string name)
        {
            PropertyInfo[] properties = my.GetType().GetProperties();

            foreach (var i in properties)
            {
                if (i.Name == name)
                {
                    return(i.GetValue(my));
                }
            }

            return(null);
        }
예제 #3
0
        public MyUser ToUser(MyUserDataGrid my)
        {
            List <int> roles      = new List <int>();
            List <int> categories = new List <int>();

            List <string> rolesNames = my.Roles.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();

            foreach (var i in rolesNames)
            {
                roles.Add(GetRoleIdByName(i));
            }

            List <string> categoriesNames = my.Categories.Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).ToList();

            foreach (var i in categoriesNames)
            {
                categories.Add(GetCategoryIdByName(i));
            }


            return(new MyUser(my.Id, my.Email, my.Password, my.Birthday,
                              my.Name, my.Surname, my.FathersName, my.Phone, my.City,
                              my.CompanyDetails, my.UserDetails, roles, categories));
        }
예제 #4
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            foreach (IValidator i in this.Validators)
            {
                i.Validate();
            }

            if (IsValid)
            {
                MyUserDataGrid my = new MyUserDataGrid();
                my.Id          = userToEdit.Id;
                my.Email       = userToEdit.Email;
                my.Password    = userToEdit.Password;
                my.Birthday    = DateTime.Parse(userBirthay.Value);
                my.Name        = userName.Text;
                my.Surname     = userSurname.Text;
                my.FathersName = userFathersName.Text;
                my.Phone       = userPhone.Text;
                my.City        = userCity.SelectedValue;
                my.UserDetails = detail.Id;

                StringBuilder roles = new StringBuilder();
                for (int i = 0; i < userToEdit.Roles.Count; i++)
                {
                    if (i == userToEdit.Roles.Count - 1)
                    {
                        roles.Append(userManager.GetRoleNameById(userToEdit.Roles[i]));
                    }
                    else
                    {
                        roles.Append(userManager.GetRoleNameById(userToEdit.Roles[i]) + ", ");
                    }
                }

                my.Roles = roles.ToString();
                roles.Clear();

                for (int i = 0; i < userCategories.Items.Count; i++)
                {
                    if (userCategories.Items[i].Selected)
                    {
                        if (i == userCategories.Items.Count - 1)
                        {
                            roles.Append(userCategories.Items[i].Text);
                        }
                        else
                        {
                            roles.Append(userCategories.Items[i].Text + ", ");
                        }
                    }
                }

                my.Categories = roles.ToString();

                userBase.Save(my);

                MyUserDetail    ndetail = new MyUserDetail();
                MyJobExperience nexp    = new MyJobExperience();
                MyEducation     nedu    = new MyEducation();

                ndetail.Id            = detail.Id;
                ndetail.Header        = txtVacancyHeader.Text;
                ndetail.Salary        = Convert.ToDecimal(txtSalary.Text);
                ndetail.Description   = txtDesc.Text;
                ndetail.Education     = edu.Id;
                ndetail.JobExperience = exp.Id;

                nexp.Id      = exp.Id;
                nexp.Company = txtCompany.Text;
                nexp.City    = txtCityExp.Text;
                nexp.Post    = txtPost.Text;
                nexp.Start   = DateTime.Parse(txtStartDate.Text);
                nexp.End     = DateTime.Parse(txtEndDate.Text);
                nexp.Desc    = txtDesc.Text;

                nedu.Id         = edu.Id;
                nedu.Level      = dropEduLevel.SelectedValue;
                nedu.Place      = txtPlace.Text;
                nedu.Speciality = txtSpeciality.Text;

                userManager.EditEducation(nedu);
                userManager.EditJobExp(nexp);

                if (nedu.Id == -1 || nexp.Id == -1)
                {
                    ndetail.Education     = userManager.GetLastEduId();
                    ndetail.JobExperience = userManager.GetLastJobExpId();
                }

                resumeBase.Save(ndetail);

                Response.Redirect("~/Employee");
            }
        }
예제 #5
0
        protected void repUsers_ItemCommand1(object source, RepeaterCommandEventArgs e)
        {
            #region Delete
            if (e.CommandName == "Delete")
            {
                int id = Convert.ToInt32(e.CommandArgument);
                rep.Delete(id);
                UpdateData();
            }
            #endregion

            #region Edit
            if (e.CommandName == "Edit")
            {
                int id = Convert.ToInt32(e.CommandArgument);


                MyUserDataGrid my = rep.GetEntityById(id) as MyUserDataGrid;

                for (int i = 0; i < e.Item.Controls.Count; i++)
                {
                    TextBox t = e.Item.Controls[i] as TextBox;
                    if (t != null)
                    {
                        t.Style.Add("display", "block");
                        t.Text = GetPropertyValue(my, t.ToolTip).ToString();
                    }
                    else
                    {
                        DropDownList lst = e.Item.Controls[i] as DropDownList;

                        if (lst != null)
                        {
                            lst.Style.Add("display", "block");
                            List <MyCity> cities = cityRep.GetAll();
                            lst.DataSource = cities.Select(c => c.Name);
                            lst.DataBind();

                            lst.SelectedValue = my.City;
                        }
                    }
                }

                int index = -1;
                for (int i = 0; i < repUsers.Items.Count; i++)
                {
                    if (repUsers.Items[i] == e.Item)
                    {
                        index = i;
                    }
                }

                ViewState.Add("EditedId", id);
                ViewState.Add("EditedIndex", index);

                btnSave.Style.Add("display", "inline");
                btnCancel.Style.Add("display", "inline");

                isEditing = true;
            }
            #endregion

            #region Add

            if (e.CommandName == "Add")
            {
                List <MyUserDataGrid> users = rep.GetAll();
                MyUserDataGrid        my    = new MyUserDataGrid()
                {
                    Roles = "Admin"
                };
                users.Add(my);

                repUsers.DataSource = users;
                repUsers.DataBind();

                RepeaterItem item = repUsers.Items.OfType <RepeaterItem>().ElementAt(repUsers.Items.Count - 1);

                for (int i = 0; i < item.Controls.Count; i++)
                {
                    TextBox t = item.Controls[i] as TextBox;
                    if (t != null)
                    {
                        t.Style.Add("display", "block");
                        object obj = GetPropertyValue(my, t.ToolTip);
                        t.Text = (obj == null)? "" : obj.ToString();
                    }
                    else
                    {
                        DropDownList lst = item.Controls[i] as DropDownList;

                        if (lst != null)
                        {
                            lst.Style.Add("display", "block");
                            List <MyCity> cities = cityRep.GetAll();
                            lst.DataSource = cities.Select(c => c.Name);
                            lst.DataBind();

                            lst.SelectedValue = my.City;
                        }
                    }
                }

                int index = -1;
                for (int i = 0; i < repUsers.Items.Count; i++)
                {
                    if (repUsers.Items[i] == item)
                    {
                        index = i;
                    }
                }

                ViewState.Add("EditedId", -1);
                ViewState.Add("EditedIndex", index);

                btnSave.Style.Add("display", "inline");
                btnCancel.Style.Add("display", "inline");

                isEditing = true;
            }

            #endregion
        }
예제 #6
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            this.Validate();

            int index = Convert.ToInt32(ViewState["EditedIndex"]);
            int id    = Convert.ToInt32(ViewState["EditedId"]);

            RepeaterItem   item = repUsers.Items[index];
            MyUserDataGrid my   = new MyUserDataGrid();

            if (id != -1)
            {
                my = rep.GetEntityById(id) as MyUserDataGrid;
            }

            for (int i = 0; i < item.Controls.Count; i++)
            {
                TextBox t = item.Controls[i] as TextBox;
                if (t != null)
                {
                    string propName = t.ToolTip;

                    switch (propName)
                    {
                    case "Email":
                        my.Email = t.Text;
                        break;

                    case "Password":
                        if (my.Password != t.Text)
                        {
                            my.Password = t.Text;
                        }
                        break;

                    case "Birthday":
                        DateTime birth = new DateTime();
                        DateTime.TryParse(t.Text, out birth);
                        if (my.Birthday != birth && birth != new DateTime())
                        {
                            my.Birthday = birth;
                        }
                        break;

                    case "Name":
                        if (my.Name != t.Text)
                        {
                            my.Name = t.Text;
                        }
                        break;

                    case "Surname":
                        if (my.Surname != t.Text)
                        {
                            my.Surname = t.Text;
                        }
                        break;

                    case "FathersName":
                        if (my.FathersName != t.Text)
                        {
                            my.FathersName = t.Text;
                        }
                        break;

                    case "Phone":
                        if (my.Phone != t.Text)
                        {
                            my.Phone = t.Text;
                        }
                        break;

                    default:
                        break;
                    }

                    t.Style.Add("display", "none");
                }
                else
                {
                    DropDownList lst = item.Controls[i] as DropDownList;

                    if (lst != null)
                    {
                        if (my.City != lst.SelectedValue)
                        {
                            my.City = lst.SelectedValue;
                        }

                        lst.Style.Add("display", "none");
                    }
                }
            }

            rep.Save(my);

            if (id == -1)
            {
                id = rep.GetAll().Max(u => u.Id);
                UserRepositoryBase b = rep as UserRepositoryBase;

                b.AddRole(id, "Admin");
            }

            ViewState.Add("EditedId", -1);
            ViewState.Add("EditedIndex", -1);

            btnSave.Style.Add("display", "none");
            btnCancel.Style.Add("display", "none");

            isEditing = false;

            UpdateData();
        }