Ejemplo n.º 1
0
        public List <OrganizeUnit> GetUnit()
        {
            List <OrganizeUnit> OU  = new List <OrganizeUnit>();
            SqlConnection       con = null;

            try
            {
                con = connect("DBConnectionString");
                String        selectSTR = "SELECT * FROM OrganizeUnit_2020";
                SqlCommand    cmd       = new SqlCommand(selectSTR, con);
                SqlDataReader dr        = cmd.ExecuteReader(CommandBehavior.CloseConnection);
                while (dr.Read())
                {
                    OrganizeUnit Unit = new OrganizeUnit();
                    Unit.Id       = Convert.ToInt32(dr["UnitId"]);
                    Unit.Unitname = (string)dr["UnitName"];
                    OU.Add(Unit);
                }
                return(OU);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
        }
Ejemplo n.º 2
0
        private void GetApartmentId(OrganizeUnit unit)
        {
            int           id  = 0;
            SqlConnection con = null;

            try
            {
                con = connect("DBConnectionString");
                String        selectSTR = "select * from Apartment_2020 where ApartmentTypeId is null";
                SqlCommand    cmd1      = new SqlCommand(selectSTR, con);
                SqlDataReader dr        = cmd1.ExecuteReader(CommandBehavior.CloseConnection);
                dr.Read();
                id = Convert.ToInt32(dr["UnitId"]);
            }
            catch (Exception ex)
            {
                throw (ex);
            }

            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
            UpdateApartmentType(unit.ApartmentType1, id);
        }
Ejemplo n.º 3
0
        private String BuildInsertCommand(OrganizeUnit unit)
        {
            String        command;
            StringBuilder sb = new StringBuilder();

            string G = unit.Numofguides.ToString();
            string R = unit.Numofresidents.ToString();

            sb.AppendFormat("Values('{0}', '{1}','{2}', '{3}','{4}','{5}')", unit.Unitname, unit.Numofresidents, unit.Numofguides, unit.City, unit.Street_hnumber, unit.Unittype);
            String prefix = "INSERT INTO OrganizeUnit_2020" + "(UnitName,NumOfResidents,NumOfGuides,City,Street_HNumber,UnitType)";

            command = prefix + sb.ToString();
            return(command);
        }
Ejemplo n.º 4
0
        public void PostUnit(OrganizeUnit unit)
        {
            SqlConnection con;
            SqlCommand    cmd;

            try
            {
                con = connect("DBConnectionString"); // create the connection
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            String cStr = BuildInsertCommand(unit);

            cmd = CreateCommand(cStr, con);
            try
            {
                int numEffected = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                }
            }
            if (unit.Unittype == "דירה")
            {
                GetApartmentId(unit);
            }
        }
 // POST api/<controller>
 public void Post([FromBody] OrganizeUnit unit)
 {
     unit.PostUnit();
 }
        // GET api/<controller>
        public List <OrganizeUnit> Get()
        {
            OrganizeUnit OU = new OrganizeUnit();

            return(OU.GetOrganizeUnit());
        }
        // PUT api/<controller>/5
        public void Put(int id, [FromBody] OrganizeUnit unit)
        {
            OrganizeUnit u = new OrganizeUnit();

            u.PutOrganizeUnit(unit);
        }