Example #1
0
        protected void ProjectGridview_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                int rowIndex = Convert.ToInt32(e.CommandArgument);
                int projId = Convert.ToInt32(ProjectGridview.Rows[rowIndex].Cells[0].Text);


                using (Storage db = new Storage())
                {

                    DAL.Project proj = db.Projects.Include("Employees").Include("Tasks").Where(p => p.ProjectCode == projId).FirstOrDefault();

                    if (proj != null)
                    {

                        proj.Status = (proj.Status) ? false : true;
                        db.SaveChanges();
                    }

                    ProjectGridview.DataBind();
                }

            }
            catch (Exception ex)
            {
                Loger.Log(Response, ex);
            }
        }
Example #2
0
        protected void UserGridView_SelectedIndexChanged(object sender, GridViewCommandEventArgs e)
        {
            try
            {
                int rowIndex = Convert.ToInt32(e.CommandArgument);
                string Login = UserGridView.Rows[rowIndex].Cells[0].Text;


                using (Storage db = new Storage())
                {

                    DAL.User cu = db.Users.Include("UserRole").Where(u => u.Login == Login).FirstOrDefault();

                    if (cu != null)
                    {

                        cu.Status = (cu.Status) ? false : true;
                        db.SaveChanges();
                    }

                    UserGridView.DataBind();
                }

            }
            catch (Exception ex)
            {
                Loger.Log(Response, ex);
            }
        }
Example #3
0
        protected void ProjCreateBtn_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {

                try
                {
                    using (Storage db = new Storage())
                    {

                        Project p = new Project();

                        p.Name = ProjNameTb.Text;
                        p.Status = ProjStatus.SelectedValue == "0" ? false : true;

                        foreach (ListItem li in MemberList.Items)
                        {
                            if (li.Selected)
                            {
                                DAL.User su = db.Users.Where(u => u.Login == li.Value).Select(u => u).FirstOrDefault();
                                p.Employees.Add(su);
                            }
                        }

                        db.Projects.Add(p);
                        db.SaveChanges();

                        ResetProjectCreateForm();
                        ProjectGridview.DataBind();
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Проект был успешно добавлен')", true);

                    }

                }
                catch (Exception ex)
                {
                    Loger.Log(Response, ex);
                }
            }

        }
Example #4
0
        protected void CreateUserBtn_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                try
                {
                    using (Storage db = new Storage())
                    {
                        if (!db.Users.Where(u => u.Login == LoginTb.Text).Any())
                        {
                            DAL.User new_user = new User();

                            new_user.Login = LoginTb.Text;
                            new_user.Name = (string.IsNullOrEmpty(NameTb.Text) || string.IsNullOrWhiteSpace(NameTb.Text)) ? null : NameTb.Text;
                            new_user.Surname = (string.IsNullOrEmpty(SurnameTb.Text) || string.IsNullOrWhiteSpace(SurnameTb.Text)) ? null : SurnameTb.Text;
                            new_user.Password = CryptoProvider.GetMD5Hash(PasswordTb.Text);
                            new_user.Status = StatusList.SelectedValue == "0" ? false : true;
                            new_user.UserRole = db.Roles.Where(r => r.Name == RoleList.SelectedValue).First();

                            db.Users.Add(new_user);
                            db.SaveChanges();

                            ResetUserCreateForm();
                            UserGridView.DataBind();
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Пользователь был успешно добавлен')", true);
                        }
                        else
                        {
                            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Пользователь с таким логином уже существует')", true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Loger.Log(Response, ex);
                }
            }

        }