void DeleteRowButtonClick(object sender, EventArgs e)
        {
            ImageButton button = (ImageButton)sender;
            {
                SaveChanges();
                CompetitionDataContext competitionDataBase = new CompetitionDataContext();
                var userIdParam   = Session["UserID"];
                int userId        = Convert.ToInt32(userIdParam);
                var applicationId = Session["ApplicationID"];
                int appid         = Convert.ToInt32(applicationId);
                int partnerid     = Convert.ToInt32(button.CommandArgument);

                zPartnersTable currentPartner = (from a in competitionDataBase.zPartnersTable
                                                 where a.Active == true && a.ID == partnerid
                                                 join b in competitionDataBase.zApplicationAndPartnersMappingTable
                                                 on a.ID equals b.FK_PartnersTable
                                                 where b.Active == true && b.FK_Application == appid
                                                 select a).FirstOrDefault();
                currentPartner.Active = false;
                competitionDataBase.SubmitChanges();

                zApplicationAndPartnersMappingTable currentLink =
                    (from a in competitionDataBase.zApplicationAndPartnersMappingTable
                     where a.Active == true && a.FK_PartnersTable == partnerid &&
                     a.FK_Application == appid
                     select a).FirstOrDefault();

                currentLink.Active = false;
                competitionDataBase.SubmitChanges();
                Response.Redirect("ChooseApplicationAction.aspx");
            }
        }
        protected void AddRowButton_Click(object sender, EventArgs e)
        {
            SaveChanges();
            CompetitionDataContext competitionDataBase = new CompetitionDataContext();
            var userIdParam   = Session["UserID"];
            int userId        = Convert.ToInt32(userIdParam);
            var applicationId = Session["ApplicationID"];
            int appid         = Convert.ToInt32(applicationId);


            zPartnersTable newPartner = new zPartnersTable();

            newPartner.Active = true;
            newPartner.Role   = false;
            competitionDataBase.zPartnersTable.InsertOnSubmit(newPartner);
            competitionDataBase.SubmitChanges();

            zApplicationAndPartnersMappingTable newLink = new zApplicationAndPartnersMappingTable();

            newLink.Active           = true;
            newLink.FK_Application   = appid;
            newLink.FK_PartnersTable = newPartner.ID;
            competitionDataBase.zApplicationAndPartnersMappingTable.InsertOnSubmit(newLink);
            competitionDataBase.SubmitChanges();
            Response.Redirect("ChooseApplicationAction.aspx");
        }
        public void SaveChanges()
        {
            CompetitionDataContext competitionDataBase = new CompetitionDataContext();

            foreach (GridViewRow currentRow in PartnersGV.Rows)
            {
                Label    partnerID  = (Label)currentRow.FindControl("ID");
                TextBox  surname    = (TextBox)currentRow.FindControl("Surname");
                TextBox  name       = (TextBox)currentRow.FindControl("Name");
                TextBox  patronymic = (TextBox)currentRow.FindControl("Patronymic");
                CheckBox role       = (CheckBox)currentRow.FindControl("Role");

                if (partnerID != null)
                {
                    zPartnersTable currentpartner = (from a in competitionDataBase.zPartnersTable
                                                     where a.ID == Convert.ToInt32(partnerID.Text)
                                                     select a).FirstOrDefault();
                    if (currentpartner != null)
                    {
                        if (surname.Text.Any() && name.Text.Any() && patronymic.Text.Any())
                        {
                            currentpartner.Surname    = surname.Text;
                            currentpartner.Name       = name.Text;
                            currentpartner.Patronymic = patronymic.Text;
                            currentpartner.Role       = role.Checked;
                            competitionDataBase.SubmitChanges();
                        }
                    }
                }
            }
        }
        public bool IsApplicationReadyToSend(int applicationId)
        {
            List <zBlockTable> blockList = (from a in _competitionDataBase.zBlockTable
                                            where a.Active == true
                                            select a).ToList();
            zApplicationTable currentApplication = (from a in _competitionDataBase.zApplicationTable
                                                    where a.ID == applicationId &&
                                                    a.Active == true
                                                    select a).FirstOrDefault();

            if (currentApplication == null)
            {
                return(false);
            }
            if (currentApplication.StartProjectDate == null)
            {
                return(false);
            }
            if (currentApplication.EndProjectDate == null)
            {
                return(false);
            }
            List <zPartnersTable> one = (from a in _competitionDataBase.zPartnersTable
                                         where a.Active == true && a.Role == true
                                         select a).ToList();
            zPartnersTable currentone = (from a in _competitionDataBase.zPartnersTable
                                         where a.Active == true && a.Role == true
                                         join b in _competitionDataBase.zApplicationAndPartnersMappingTable
                                         on a.ID equals b.FK_PartnersTable
                                         where b.Active == true && b.FK_Application == Convert.ToInt32(currentApplication.ID)
                                         select a).FirstOrDefault();

            if (one != null && currentone != null)
            {
                List <int> lider = (from a in one
                                    where a.Name == currentone.Name &&
                                    a.Surname == currentone.Surname &&
                                    a.Patronymic == currentone.Patronymic
                                    select a.ID).ToList();
                if (lider.Count > 1)
                {
                    return(false);
                }
            }
            List <zPartnersTable> two = (from a in _competitionDataBase.zPartnersTable
                                         where a.Active == true && a.Role == false
                                         select a).ToList();
            zPartnersTable currenttwo = (from a in _competitionDataBase.zPartnersTable
                                         where a.Active == true && a.Role == false
                                         join b in _competitionDataBase.zApplicationAndPartnersMappingTable
                                         on a.ID equals b.FK_PartnersTable
                                         where b.Active == true && b.FK_Application == Convert.ToInt32(currentApplication.ID)
                                         select a).FirstOrDefault();

            if (two != null && currenttwo != null)
            {
                List <int> teamuser = (from a in two
                                       where a.Name == currenttwo.Name &&
                                       a.Surname == currenttwo.Surname &&
                                       a.Patronymic == currenttwo.Patronymic
                                       select a.ID).ToList();

                if (teamuser.Count >= 2)
                {
                    return(false);
                }
            }
            foreach (zBlockTable block in blockList)
            {
                if (GetStatusIdForBlockInApplication(block.ID, applicationId) != statusAllData)
                {
                    return(false);
                }
            }
            return(true);
        }
        protected void PartnersGV_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            CompetitionDataContext competitionDataBase = new CompetitionDataContext();
            var userIdParam   = Session["UserID"];
            int userId        = Convert.ToInt32(userIdParam);
            var applicationId = Session["ApplicationID"];
            int appid         = Convert.ToInt32(applicationId);

            Label idLabel = (Label)e.Row.FindControl("ID");

            if (idLabel != null)
            {
                Label error1 = (Label)e.Row.FindControl("Error1");
                Label error2 = (Label)e.Row.FindControl("Error2");

                List <zPartnersTable> one = (from a in competitionDataBase.zPartnersTable
                                             where a.Active == true && a.Role == true
                                             select a).ToList();
                zPartnersTable currentone = (from a in competitionDataBase.zPartnersTable
                                             where a.Active == true && a.Role == true && a.ID == Convert.ToInt32(idLabel.Text)
                                             select a).FirstOrDefault();
                if (one != null && currentone != null)
                {
                    List <int> lider = (from a in one
                                        where a.Name == currentone.Name &&
                                        a.Surname == currentone.Surname &&
                                        a.Patronymic == currentone.Patronymic
                                        select a.ID).ToList();
                    if (lider.Count > 1)
                    {
                        error1.Visible = true;
                    }
                    else
                    {
                        error1.Visible = false;
                    }
                }

                List <zPartnersTable> two = (from a in competitionDataBase.zPartnersTable
                                             where a.Active == true && a.Role == false
                                             select a).ToList();
                zPartnersTable currenttwo = (from a in competitionDataBase.zPartnersTable
                                             where a.Active == true && a.Role == false && a.ID == Convert.ToInt32(idLabel.Text)
                                             select a).FirstOrDefault();
                if (two != null && currenttwo != null)
                {
                    List <int> teamuser = (from a in two
                                           where a.Name == currenttwo.Name &&
                                           a.Surname == currenttwo.Surname &&
                                           a.Patronymic == currenttwo.Patronymic
                                           select a.ID).ToList();

                    if (teamuser.Count >= 2)
                    {
                        error2.Visible = true;
                    }
                    else
                    {
                        error2.Visible = false;
                    }
                }
            }
        }