示例#1
0
        public void AddUser(MyUser my, MyCompanyDetail companyDetail, MyUserDetail userDetail)
        {
            User u = new User();

            u.Email       = my.Email;
            u.Password    = my.Password;
            u.Birthday    = my.Birthday;
            u.Name        = my.Name;
            u.Surname     = my.Surname;
            u.FathersName = my.FathersName;
            u.Phone       = my.Phone;
            u.CityId      = GetCityIdByName(my.City);

            if (companyDetail != null)
            {
                AddCompanyDetail(companyDetail);
                int count = ctx.CompanyDetails.Count();
                u.CompanyDetails = ctx.CompanyDetails.Max(d1 => d1.Id);
            }
            if (userDetail != null)
            {
                AddUserDetail(userDetail);
                int count = ctx.UserDetails.Count();
                u.UserDetails = ctx.UserDetails.Max(d1 => d1.Id);
            }

            ctx.Users.Add(u);
            ctx.SaveChanges();

            u.Id = ctx.Users.Max(user => user.Id);

            AddUserRoles(my, u);
            AddUserCategories(my, u);
        }
示例#2
0
 public void AddCompanyDetail(MyCompanyDetail companyDetail)
 {
     ctx.CompanyDetails.Add(new CompanyDetail()
     {
         Name          = companyDetail.Name,
         TypeOfCompany = companyDetail.TypeOfCompany, WebSite = companyDetail.WebSite
     });
     ctx.SaveChanges();
 }
示例#3
0
        public MyCompanyDetail GetCompanyDetailById(int id)
        {
            CompanyDetail   detail = ctx.CompanyDetails.First(d => d.Id == id);
            MyCompanyDetail my     = new MyCompanyDetail();

            my.Id            = detail.Id;
            my.Name          = detail.Name;
            my.WebSite       = detail.WebSite;
            my.TypeOfCompany = detail.TypeOfCompany;

            return(my);
        }
示例#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          = 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");
            }
        }
示例#5
0
        public object GetPropertyValue(MyCompanyDetail my, string name)
        {
            PropertyInfo[] properties = my.GetType().GetProperties();

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

            return(null);
        }
示例#6
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            foreach (IValidator i in this.Validators)
            {
                i.Validate();
            }

            if (IsValid)
            {
                MyUser my = new MyUser();
                my.Email       = userEmail.Text;
                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.Add(userManager.GetRoleIdByName("Employer"));

                MyCompanyDetail detail = new MyCompanyDetail();
                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();
                List <int>    categoryId = new List <int>();

                foreach (var c in categories)
                {
                    categoryId.Add(userManager.GetCategoryIdByName(c));
                }

                my.Categories = categoryId;

                userManager.AddUser(my, detail, null);

                Response.Redirect("~/SignIn.aspx");
            }
        }
示例#7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            userManager = IoCContainer.ServiceLocator.Resolve <IDbManager>();
            userBase    = (UserRepositoryBase)IoCContainer.ServiceLocator.Resolve <IRepository <MyUserDataGrid> >();
            companyBase = (CompanyRepositoryBase)IoCContainer.ServiceLocator.Resolve <IRepository <MyCompanyDetail> >();

            user    = this.Session["CurrentUser"] as MyUser;
            company = userManager.GetCompanyDetailById(user.CompanyDetails);

            if (!IsPostBack)
            {
                userCategories.DataSource = userManager.GetCategories().Select(c => c.Name).ToList();
                userCategories.DataBind();

                userCity.DataSource = userManager.GetCities();
                userCity.DataBind();

                userPassword.Text         = user.Password;
                companyName.Text          = company.Name;
                companyType.SelectedIndex = company.TypeOfCompany;
                companyWebSite.Text       = company.WebSite;

                userCity.SelectedValue = user.City;
                userBirthay.Value      = user.Birthday.ToShortDateString();
                userName.Text          = user.Name;
                userSurname.Text       = user.Surname;
                userFathersName.Text   = user.FathersName;
                userPhone.Text         = user.Phone;

                foreach (ListItem i in userCategories.Items)
                {
                    if (user.Categories.Contains(userManager.GetCategoryIdByName(i.Text)))
                    {
                        i.Selected = true;
                    }
                }
            }
        }
示例#8
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);


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

                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");
                            if (my.TypeOfCompany == 0)
                            {
                                lst.SelectedValue = "Direct Employer";
                            }
                            else
                            {
                                lst.SelectedValue = "Active Agency";
                            }
                        }
                    }
                }

                int index = -1;
                for (int i = 0; i < repCompanies.Items.Count; i++)
                {
                    if (repCompanies.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 <MyCompanyDetail> users = rep.GetAll();
                MyCompanyDetail        my    = new MyCompanyDetail();
                users.Add(my);

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

                RepeaterItem item = repCompanies.Items.OfType <RepeaterItem>().ElementAt(repCompanies.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");

                            lst.SelectedValue = "Direct Employer";
                        }
                    }
                }

                int index = -1;
                for (int i = 0; i < repCompanies.Items.Count; i++)
                {
                    if (repCompanies.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
        }
示例#9
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 = repCompanies.Items[index];
            MyCompanyDetail my   = new MyCompanyDetail();

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

            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 "Name":
                        if (my.Name != t.Text)
                        {
                            my.Name = t.Text;
                        }
                        break;

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

                    default:
                        break;
                    }

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

                    if (lst != null)
                    {
                        if (lst.SelectedIndex == 0)
                        {
                            my.TypeOfCompany = 0;
                        }
                        else
                        {
                            my.TypeOfCompany = 1;
                        }
                    }
                }
            }

            rep.Save(my);

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

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

            isEditing = false;

            UpdateData();
        }