public List<DownloadUserForm> GetByFileID(int id)
        {
            List<DownloadUserForm> res = new List<DownloadUserForm>();
            using (StoredProcedure sp = new StoredProcedure(string.Format("SELECT * FROM DownloadUserForms WHERE FileID = @FileID")))
            {
                sp.command.CommandType = CommandType.Text;
                sp.Params.Add("FileID", SqlDbType.NVarChar).Value = id;
                using (SqlDataReader r = (SqlDataReader)sp.ExecuteReader())
                {
                    if (r != null)
                    {

                        while (r.Read())
                        {
                            DownloadUserForm d = new DownloadUserForm();
                            d.Url = r.GetString(r.GetOrdinal("Url"));
                            d.FileID = r.GetInt32(r.GetOrdinal("FileID"));
                            d.ID = r.GetInt32(r.GetOrdinal("ID"));
                            d.Email = r.GetString(r.GetOrdinal("Email"));
                            d.FirstName = r.GetString(r.GetOrdinal("FirstName"));
                            d.LastName = r.GetString(r.GetOrdinal("LastName"));
                            res.Add(d);
                        }

                    }
                }
            }
            return res;
        }
        public DownloadUserForm GetByIds(int id)
        {
            DownloadUserForm res = new DownloadUserForm();
            using (StoredProcedure sp = new StoredProcedure(string.Format("SELECT * FROM DownloadUserForms WHERE ID = ", id)))
            {
                sp.command.CommandType = CommandType.Text;
                using (SqlDataReader r = (SqlDataReader)sp.ExecuteReader())
                {
                    if (r != null)
                    {
                        while (r.Read())
                        {

                        }
                    }
                }
            }
            return res;
        }
 public DownloadUserForm GetByGuid(string url)
 {
     DownloadUserForm res = new DownloadUserForm();
     using (StoredProcedure sp = new StoredProcedure(string.Format("SELECT * FROM DownloadUserForms WHERE Url = @Url")))
     {
         sp.command.CommandType = CommandType.Text;
         sp.Params.Add("Url", SqlDbType.NVarChar).Value = url;
         using (SqlDataReader r = (SqlDataReader)sp.ExecuteReader())
         {
             if (r != null)
             {
                 while (r.Read())
                 {
                     res.Url = r.GetString(r.GetOrdinal("Url"));
                     res.FileID = r.GetInt32(r.GetOrdinal("FileID"));
                 }
             }
         }
     }
     return res;
 }
        protected void imgSubmit_Click(object sender, EventArgs e)
        {
            if (IsValid())
            {
                //IsFormSubmitted = true;
                try
                {
                    //SeminarRegistration sr = new SeminarRegistration
                    //{
                    //    CompanyName = txtCompanyName.Text,
                    //    Email = txtEmail.Text,
                    //    FIO = txtFio.Text,
                    //    JobAction = Convert.ToInt32(ddlFirmAction.SelectedValue),
                    //    JobTitle = txtJobTitle.Text,
                    //    TypeID = 1,
                    //    Site = txtSite.Text.ToLower().StartsWith("http://") ? txtSite.Text : "http://" + txtSite.Text
                    //};

                    //SeminarRegistrations.Add(sr);
            //        SendMail();

                    try
                    {
                        Session["email"] = txtEmail.Text;
                        Session["firstname"] = txtFirstName.Text;
                        Session["lastname"] = txtLastName.Text;
                    }
                    catch (Exception)
                    {

                        throw;
                    }
                    int id = 0;
                    if (Session["id"] != null && !string.IsNullOrEmpty(Session["id"].ToString()))
                    {
                        try
                        {
                            id = Int32.Parse(Session["id"].ToString());
                        }
                        catch (Exception)
                        {
                            id = -1;
                        }
                    }
                    DownloadUserForm duf = new DownloadUserForm{Email=txtEmail.Text,
                                            FirstName = txtFirstName.Text,
                                            LastName = txtLastName.Text,
                                            FileID = id};

                    DownloadUserForms manager = new DownloadUserForms();
                    string urlGuid = manager.InsertForm(duf);

                    IsFormSubmitted = true;
                    hlLink.NavigateUrl = "~/DownloadFile.aspx?guid=" + urlGuid;
                    phForm.Visible = false;
                    phLink.Visible = true;
                    Session.Remove("id");
                }
                catch (Exception exc)
                {
                    IsFormSubmitted = false;
                    Logger.LogException(exc, "DownloadFileForm.ascx");
                    lbError.Visible = true;
                    lbError.ForeColor = Color.Red;
                    lbError.Text = "Произошла внутрення ошибка. Обратитесь к администратору.";
                }

            }
            else
            {
                lbError.Visible = true;
                lbError.ForeColor = Color.Red;
                lbError.Text = "Просьба заполните все поля";
            }
        }
 public string InsertForm(DownloadUserForm duf)
 {
     bool ifExists = false;
     using (StoredProcedure sp = new StoredProcedure("SELECT * FROM DownloadUserForms WHERE FileID=@FileID AND Email = @Email AND CreateDate > @CreateDate"))
     {
         sp.command.CommandType = CommandType.Text;
         sp.Params.Add("Email", SqlDbType.NVarChar).Value = duf.Email.ToLower();
         sp.Params.Add("FileID", SqlDbType.Int).Value = duf.FileID;
         sp.Params.Add("CreateDate", SqlDbType.DateTime).Value = DateTime.Now.AddHours(-1);
         var reader = sp.ExecuteReader();
         if (reader != null && reader.Read())
         {
             ifExists = true;
             duf.Url = reader.GetString(reader.GetOrdinal("Url"));
         }
     }
     if (ifExists) return duf.Url;
     using (
             StoredProcedure sp =
                 new StoredProcedure(@"INSERT INTO DownloadUserForms(FirstName, LastName, Email, FileID, Url)
                                     VALUES(@FirstName, @LastName, @Email, @FileID, @Url)"))
     {
         sp.command.CommandType = CommandType.Text;
         sp.Params.Add("FirstName", SqlDbType.NVarChar).Value = duf.FirstName;
         sp.Params.Add("LastName", SqlDbType.NVarChar).Value = duf.LastName;
         sp.Params.Add("Email", SqlDbType.NVarChar).Value = duf.Email.ToLower();
         sp.Params.Add("FileID", SqlDbType.Int).Value = duf.FileID;
         duf.Url = Guid.NewGuid().ToString();
         sp.Params.Add("Url", SqlDbType.NVarChar).Value = duf.Url;
         sp.ExecuteNonQuery();
     }
     return duf.Url;
 }