コード例 #1
0
    protected void InsertFarm(object sender, EventArgs e)
    {
        var farmManager =
            new FarmManager(ConfigurationManager.ConnectionStrings["AdditionalInformation"].ConnectionString);
        var farm = farmManager.GetFarmByName(FermaName.Text);

        if (farm != null)
        {
            FarmValidation.Text      = "Ferma " + FermaName.Text + " exista deja!";
            FarmValidation.Visible   = true;
            FarmValidation.ForeColor = Color.Red;
        }
        else
        {
            farm = new FCCL_DAL.Entities.Ferme_CCL
            {
                Cod                = FermaCod.Text,
                CodPostal          = CodPostal.Text,
                Email              = FarmEmail.Text,
                FabricaId          = Convert.ToInt32(Asociatia.SelectedValue),
                Fax                = Fax.Text,
                Ferme              = "F",
                FermierId          = 0,
                Judet              = Judet.SelectedValue,
                JudetId            = Convert.ToInt32(Judet.SelectedValue),
                Nume               = FermaName.Text,
                Numar              = Numar.Text,
                Oras               = Localitate.Text,
                PersoanaDeContact  = PersContact.Text,
                Telefon            = Telefon.Text,
                TelPersoanaContact = TelPersContact.Text,
                Strada             = Strada.Text,
                SendSms            = SendSms.Checked
            };
            var result = farmManager.InsertFarm(farm);
            if (result)
            {
                Response.Redirect("~/EditareFerme.aspx");
            }
            else
            {
                FarmValidation.Text      = "Ferma " + FermaName.Text + " nu poate fi inserata!";
                FarmValidation.Visible   = true;
                FarmValidation.ForeColor = Color.Red;
            }
        }
    }