protected void Button1_Click1(object sender, EventArgs e)
        {
            RealEstateModel db = new RealEstateModel();
            Agent           a  = new Agent();

            a.CEANumber               = txtCEANumber.Text;
            a.Email                   = txtEmail.Text;
            a.AgencyID                = int.Parse(ddlAgencyID.SelectedItem.Value);
            a.SalesPersonName         = txtSalesPersonName.Text;
            a.SalesPersonMobileNumber = txtSalesPersonMobileNumber.Text;
            db.Agents.Add(a);
            db.SaveChanges();

            if (FileUpload1.HasFile)
            {
                try
                {
                    FileUpload1.SaveAs(Server.MapPath("~/Images/Agents/") + a.AgentID + ".jpg");
                    Label3.Text = "Upload Status:File Uploaded Successfully.";
                }
                catch (Exception ex)
                {
                    Label3.Text = "Upload Status:File could not be uploaded." +
                                  "The following error occured:" + ex.Message;
                }
            }
            a.ProfilePicture = a.AgentID + ".jpg";
            db.SaveChanges();
            GridView1.DataBind();
            // SqlDataSource1.Insert();
        }
Example #2
0
        protected void btnSaveDistrict_Click(object sender, EventArgs e)
        {
            District district;

            if (ddlDistrictCode.SelectedIndex != 0)
            {
                district = model.Districts.Where(x => x.DistrictCode == ddlDistrictCode.Text).FirstOrDefault <District>();

                district.DistrictCode = txtDistrictCode.Text;
                district.DistrictName = txtDistrictName.Text;

                model.SaveChanges();
            }
            else
            {
                district = new District();

                district.DistrictCode = txtDistrictCode.Text;
                district.DistrictName = txtDistrictName.Text;
                model.Districts.Add(district);
                model.SaveChanges();
            }

            List <District> dists = model.Districts.OrderBy(x => x.DistrictCode).ToList <District>();
            List <String>   code  = new List <string>();

            foreach (District dist in dists)
            {
                string dCode = dist.DistrictCode.ToString();
                code.Add(dCode);
            }

            ddlDistrictCode.DataSource = code;
            ddlDistrictCode.DataBind();

            district = model.Districts.Where(x => x.DistrictCode == ddlDistrictCode.Text).FirstOrDefault <District>();

            txtDistrictCode.Text = district.DistrictCode;
            txtDistrictName.Text = district.DistrictName;
            txtDistrictName.DataBind();
            ddlDistrictCode.Items.Insert(0, new ListItem(string.Empty, string.Empty));
            ddlDistrictCode.SelectedIndex = 0;
        }
Example #3
0
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            RealEstateModel context = new RealEstateModel();


            Address addss = new Address();

            addss.UnitNumber  = tbx_UnitNumber.Text;
            addss.BlockNumber = tbx_BlockNumber.Text;
            addss.StreetName  = tbx_StreetName.Text;
            addss.PostalCode  = tbx_PostalCode.Text;
            addss.Email       = tbx_Email.Text;
            addss.Mobile      = tbx_Mobile.Text;
            addss.Phone       = tbx_OfficePh.Text;
            addss.Website     = tbx_Website.Text;
            context.Addresses.Add(addss);
            context.SaveChanges();


            Agency agenc = new Agency();

            agenc.AgencyName = tbx_AgencyName.Text;
            agenc.AddressID  = addss.AddressID;

            //tried
            //string v = context.Addresses.Where(x => x.PostalCode.Equals(tbx_PostalCode.Text)).Select(x => x.AddressID).ToString();
            //agenc.AddressID = Convert.ToInt32(v);

            //agenc.Address.UnitNumber = addss.UnitNumber;
            //agenc.Address.BlockNumber = addss.BlockNumber;
            //agenc.Address.StreetName = addss.StreetName;
            //agenc.Address.PostalCode = addss.PostalCode;

            //agenc.Address.Email = addss.Email;
            //agenc.Address.Mobile = addss.Mobile;
            //agenc.Address.Phone = addss.Phone;
            //agenc.Address.Website = addss.Website;

            context.Agencies.Add(agenc);
            context.SaveChanges();

            Response.Redirect("AgencyMain.aspx");
        }
Example #4
0
        protected void btnSubmitPropery_Click(object sender, EventArgs e)
        {
            RealEstateModel db = new RealEstateModel();

            Property p = new Property();
            Address  a = new Address();

            a.PostalCode  = txtPostCode.Text;
            a.BlockNumber = txtBlockNumber.Text;
            a.StreetName  = txtStreetName.Text;
            a.UnitNumber  = txtUnitNumber.Text;
            db.Addresses.Add(a);
            db.SaveChanges();

            p.ProperName      = txtPropertyName.Text;
            p.Description     = txtaDescription.Text;
            p.PricePSF        = int.Parse(txtPricePSF.Text);
            p.Rooms           = txtRooms.Text;
            p.SizePSF         = int.Parse(txtSizePSF.Text);
            p.SellerID        = int.Parse(ddlSeller.SelectedValue);
            p.AgentID         = int.Parse(ddlAgent.SelectedValue);
            p.DistrictID      = int.Parse(ddlDistrict.SelectedValue);
            p.PropertyTopDate = DateTime.Today;
            p.LeaseStartDate  = DateTime.Today;
            p.PropertyTypeID  = int.Parse(ddlPropertyType.SelectedValue);
            p.AddressID       = a.AddressID;

            db.Properties.Add(p);
            db.SaveChanges();

            PropertyImage image = new PropertyImage();

            image.PropertyID = p.PropertyID;
            db.PropertyImages.Add(image);
            db.SaveChanges();


            image.PropertyImageName = image.PropertyImageID + ".jpg";
            FileUpload1.SaveAs(Server.MapPath("~/Images/Properties/") + image.PropertyImageName);
            Util.ShowMessage("Address ID: " + p.AddressID + " " + image.PropertyImageID, this.GetType(), this);
            db.SaveChanges();
        }
Example #5
0
        private static void TestDatabase(bool insertData = false)
        {
            try
            {
                Console.Write("Creating context . . .");

                using (var db = new RealEstateModel())
                {
                    Console.WriteLine(" Done!");

                    if (insertData)
                    {
                        Console.WriteLine();
                        Console.Write("Inserting data . . .");
                        var prop = new Property {
                            Name = "Broj soba", Value = "5"
                        };
                        db.Properties.Add(prop);
                        db.SaveChanges();
                        Console.WriteLine(" Done!");
                    }

                    Console.WriteLine();
                    Console.WriteLine("Printing data:");
                    Console.WriteLine();
                    var query = from p in db.Properties select p;
                    foreach (var item in query)
                    {
                        Console.WriteLine($"{item.Name}: {item.Value}");
                    }

                    Console.WriteLine();
                    Console.WriteLine("Done!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine();
                Console.WriteLine(ex.GetType().FullName);
                Console.WriteLine();
                Console.WriteLine(ex.Message);

                if (ex.InnerException != null)
                {
                    Console.WriteLine();
                    Console.Write("Inner exception: ");
                    Console.WriteLine(ex.InnerException.GetType().FullName);
                    Console.WriteLine();
                    Console.WriteLine(ex.InnerException.Message);
                }
            }
        }
Example #6
0
        protected void Button3_Click(object sender, EventArgs e)   //save button
        {
            Property prop = db.Properties.Where(x => x.ProperName == DropDownList1.Text.ToString()).First();

            prop.PricePSF    = Convert.ToInt32(TextBox8.Text);
            prop.SizePSF     = Convert.ToInt32(TextBox7.Text);
            prop.Description = TextBox6.Text;
            prop.DistrictID  = Convert.ToInt32(DropDownList2.SelectedValue);
            db.SaveChanges();



            //Property pty = db.Properties.Where(x => x.ProperName==DropDownList3.Text.ToString()).First();

            //Address addss = db.Addresses.Where(x => x.AddressID == pty.AddressID).First();
            //District dstt = db.Districts.Where(x => x.DistrictID == pty.DistrictID).First();
            //PropertyType ptype = db.PropertyTypes.Where(x => x.PropertyTypeID == pty.PropertyTypeID).First();
            //Agent agt = db.Agents.Where(x => x.AgencyID == pty.AgentID).First();
            //Models.Seller sll = db.Sellers.Where(x => x.SellerID == pty.SellerID).First();

            //Property prop = new Property();
            //prop.PropertyID = pty.PropertyID;
            //prop.ProperName = DropDownList3.SelectedValue;
            //prop.Rooms = "";
            //var addressList = db.Addresses.Where(x => x.AddressID == addss.AddressID).ToList();
            //int addressID = addressList.IndexOf(addss);

            //prop.AddressID = addressID;

            //var districtList = db.Districts.Where(x => x.DistrictName == DropDownList2.Text).ToList();
            //int dsttID = districtList.IndexOf(dstt);

            //prop.DistrictID = dsttID;

            //var ptypeList = db.PropertyTypes.Where(x => x.PropertyTypeID == ptype.PropertyTypeID).ToList();
            //int ptypeID = ptypeList.IndexOf(ptype);

            //prop.PropertyTypeID = ptypeID;

            ////var agentList = db.Agents.Where(x => x.AgencyID == agt.AgencyID).ToList();
            ////int agentID = agentList.IndexOf(agt);

            ////prop.AgentID = agentID;

            ////var sellerList = db.Sellers.Where(x => x.SellerID == sll.SellerID).ToList();
            ////int sellerID = sellerList.IndexOf(sll);

            ////prop.SellerID = sellerID;

            //db.SaveChanges();
        }
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            //con.Open();
            //SqlCommand cmd = con.CreateCommand();
            //cmd.CommandType = CommandType.Text;
            //cmd.CommandText = ("INSERT INTO  Addresses (UnitNumber,BlockNumber,StreetName,PostalCode,Email,Mobile,Phone) values('"
            //    + tbUnitnum.Text.ToString()
            //    + "','" + tbblknum.Text.ToString()
            //    + "','" + tbStreet.Text.ToString()
            //    + "','" + tbPostcode.Text.ToString()
            //    + "','" + tbEmail.Text.ToString()
            //    + "','" + tbMobile.Text.ToString()
            //    + "','" + tbPhone.Text.ToString() + "')");
            //cmd.ExecuteNonQuery();
            //con.Close();


            RealEstateModel ctx  = new RealEstateModel();
            Address         addr = new Address();

            addr.UnitNumber  = tbUnitnum.Text.ToString();
            addr.BlockNumber = tbblknum.Text.ToString();
            addr.StreetName  = tbStreet.Text.ToString();
            addr.PostalCode  = tbPostcode.Text.ToString();
            addr.Email       = tbEmail.Text.ToString();
            addr.Mobile      = tbMobile.Text.ToString();
            addr.Phone       = tbPhone.Text.ToString();
            ctx.Addresses.Add(addr);

            ctx.SaveChanges();


            List <Address> AddrList = ctx.Addresses.ToList();

            AddrList.Count().ToString();
            Address LastAddr = new Address();

            LastAddr = AddrList.Last();


            con.Open();
            SqlCommand cmd1 = con.CreateCommand();

            cmd1.CommandType = CommandType.Text;
            cmd1.CommandText = ("INSERT INTO Sellers (SellerName, AddressID) VALUES ('" + tbName.Text.ToString() + "'," + LastAddr.AddressID.ToString() + ")");
            cmd1.ExecuteNonQuery();
            con.Close();


            Response.Redirect("SellerMainPage.aspx");
        }
        protected void btn_Update_Click(object sender, EventArgs e)
        {
            Agency agnc = context.Agencies.Where(x => x.AgencyName.Equals(tbx_AgencyName.Text)).First();

            agnc.Address.UnitNumber  = tbx_UnitNumber.Text;
            agnc.Address.BlockNumber = tbx_BlockNumber.Text;
            agnc.Address.StreetName  = tbx_StreetName.Text;
            agnc.Address.PostalCode  = tbx_PostalCode.Text;
            agnc.Address.Email       = tbx_Email.Text;
            agnc.Address.Mobile      = tbx_Mobile.Text;
            agnc.Address.Phone       = tbx_OfficePh.Text;
            agnc.Address.Website     = tbx_Website.Text;

            context.Agencies.Add(agnc);
            context.SaveChanges();
        }