Example #1
0
    //******************************** updateFoodSourceTypeIfNotExist method ********************************//
    private void updateFoodSourceTypeIfNotExist()
    {
        try
        {
            using (CCSEntities db = new CCSEntities())
            {

                dnrTypeResult = (from d in db.FoodSourceTypes
                                 where d.FoodSourceTypeID == passedDonorTypeID
                                 select d).FirstOrDefault();

                if (dnrTypeResult != null)
                {

                    //must check that new donor type does not exist prior to updating the into database
                    FoodSourceType lookupResult = (from t in db.FoodSourceTypes
                                                    where t.FoodSourceType1.Equals(txtDonorType.Text)
                                                    select t).FirstOrDefault();

                    //if the updated donor type info doesn't already exist
                    if (lookupResult == null)
                    {
                        dnrTypeResult.FoodSourceType1 = txtDonorType.Text;
                        dnrTypeResult.FoodSourceTypeID = passedDonorTypeID;

                        //process update without the confirm page
                        dnrTypeResult.FoodSourceType1 = txtDonorType.Text;
                        db.SaveChanges(); // commit changes

                        LogChange.logChange("Donor Type " + dnrTypeResult.FoodSourceType1 + " was edited.", DateTime.Now, short.Parse(Session["userID"].ToString()));
                    }
                    else
                    {
                        lblMessage.Text += txtDonorType.Text + " Donor Type exists already!<br/>";
                    }

                }
                else
                {
                    lblMessage.Text += "The Donor Type with ID " + passedDonorTypeID + " could not be found.<br/>";
                }

            } //end of using connection

        }
        catch (System.Threading.ThreadAbortException) { }
        catch (Exception ex)
        {
            LogError.logError(ex);
            Response.Redirect("../errorpages/error.aspx");
        }
    }
Example #2
0
    //****************************** insertNewDonorTypeIfNotExist ***********************************//
    private void insertNewDonorTypeIfNotExist()
    {
        try
        {
            using (CCSEntities db = new CCSEntities())
            {
                FoodSourceType donorType = new FoodSourceType();

                //must check that do not exist prior to adding into database
                FoodSourceType lookupResult = (from t in db.FoodSourceTypes
                                               where t.FoodSourceType1.Equals(txtNewDonorType.Text, StringComparison.OrdinalIgnoreCase)
                                               select t).FirstOrDefault();

                if (lookupResult != null)
                {
                    lblMessage.Text += txtNewDonorType.Text + " Donor Type exists already!<br/>";
                }
                else
                {
                    //insert the donor type in the text field to the database.
                    donorType.FoodSourceType1 = txtNewDonorType.Text.ToString();
                    db.FoodSourceTypes.Add(donorType);
                    db.SaveChanges();

                    txtNewDonorType.Text = ""; //reset the field to empty

                    LogChange.logChange("Donor Type " + donorType.FoodSourceType1 + " was added.", DateTime.Now, short.Parse(Session["userID"].ToString()));
                }
            }
        }
        catch (System.Threading.ThreadAbortException) { }
        catch (Exception ex)
        {
            LogError.logError(ex);
            Response.Redirect("../errorpages/error.aspx");
        }
    }
Example #3
0
    //******************************** loadFoodSourceType method ********************************//
    private void loadFoodSourceType()
    {
        try
        {
            using (CCSEntities db = new CCSEntities())
            {
                dnrTypeResult = (from d in db.FoodSourceTypes
                                 where d.FoodSourceTypeID == passedDonorTypeID
                                 select d).FirstOrDefault();
            }

            if (dnrTypeResult != null)
            {
                lblDonorTypeName.Text = dnrTypeResult.FoodSourceType1.ToString();
                txtDonorType.Text = dnrTypeResult.FoodSourceType1.ToString();
            }
            else
            {
                lblMessage.Text += "The Donor Type with ID " + passedDonorTypeID + " could not be found.<br/>";
            }

        }
        catch (System.Threading.ThreadAbortException) { }
        catch (Exception ex)
        {
            LogError.logError(ex);
            Response.Redirect("../errorpages/error.aspx");
        }
    }