Ejemplo n.º 1
0
    public void btnShorten2_Click(object sender, EventArgs e)
    {
        if (txtLongUrl.Text != "" && IsValidUri(txtLongUrl.Text) != false)
        {
            string baseUrl    = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";
            string shortenKey = RandomString(6);
            string finalURL   = baseUrl + shortenKey;

            LearnEFEntities  db            = new LearnEFEntities();
            tbl_shortenedUrl shortnDetails = new tbl_shortenedUrl();
            shortnDetails.longUrl  = txtLongUrl.Text;
            shortnDetails.shortUrl = finalURL;
            shortnDetails.urlKey   = shortenKey;
            shortnDetails.addedOn  = DateTime.Now;

            db.tbl_shortenedUrl.Add(shortnDetails);
            db.SaveChanges();
            //Console.Write(finalURL);
            lblShortenedUrl.InnerText = finalURL;
            btnCopy.Visible           = true;
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please specify a valid url!')", true);
        }
    }
Ejemplo n.º 2
0
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        Int32 empId = Convert.ToInt32(btnSave.CommandArgument);

        if (empId != 0)
        {
            LearnEFEntities db = new LearnEFEntities();

            Employee objEmp = new Employee()
            {
                EmpId = empId
            };
            db.Employees.Attach(objEmp);
            db.Employees.Remove(objEmp);
            db.SaveChanges();

            //reset the form and grid
            ClearEmpForm();
            PopulateEmpList();
        }
    }
Ejemplo n.º 3
0
    public void btnShorten3_Click(object sender, EventArgs e)
    {
        string baseUrl   = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";
        string customKey = txtShortCustom.Text;

        if (txtLongUrl.Text != "")
        {
            if (customKey != "" && customKey.Length <= 6 && System.Text.RegularExpressions.Regex.IsMatch(customKey, @"^[a-zA-Z0-9]+$"))
            {
                if (!IsExists(customKey))
                {
                    string           finalURL      = baseUrl + customKey;
                    LearnEFEntities  db            = new LearnEFEntities();
                    tbl_shortenedUrl shortnDetails = new tbl_shortenedUrl();
                    shortnDetails.longUrl  = txtLongUrl.Text;
                    shortnDetails.shortUrl = finalURL;
                    shortnDetails.urlKey   = customKey;
                    shortnDetails.addedOn  = DateTime.Now;
                    db.tbl_shortenedUrl.Add(shortnDetails);
                    db.SaveChanges();
                    //Console.Write(finalURL);
                    lblShortenedUrl.InnerText = finalURL;
                    //btnCopy2.Visible = true;
                    btnCopy.Visible = true;
                }
                else
                {
                    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Name has already been taken!')", true);
                }
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please specify valid custom url!')", true);
            }
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Please specify a valid url to shorten!')", true);
        }
    }
Ejemplo n.º 4
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        Int32 empId = Convert.ToInt32(btnSave.CommandArgument);

        if (empId == 0)
        {
            //INSERT
            LearnEFEntities db     = new LearnEFEntities();
            Employee        objEmp = new Employee();
            objEmp.HREmpId   = txtHREmpId.Text;
            objEmp.FirstName = txtFirstName.Text;
            objEmp.LastName  = txtLastName.Text;
            objEmp.Address   = txtAddress.Text;
            objEmp.City      = txtCity.Text;

            db.Employees.Add(objEmp);
            db.SaveChanges();
        }
        else
        {
            //UPDATE
            LearnEFEntities db = new LearnEFEntities();

            var empQuery = from emp in db.Employees
                           where emp.EmpId == empId
                           select emp;
            Employee objEmp = empQuery.Single();

            objEmp.HREmpId   = txtHREmpId.Text;
            objEmp.FirstName = txtFirstName.Text;
            objEmp.LastName  = txtLastName.Text;
            objEmp.Address   = txtAddress.Text;
            objEmp.City      = txtCity.Text;

            db.SaveChanges();
        }

        ClearEmpForm();
        PopulateEmpList();
    }