Exemplo n.º 1
0
        public BuildingBDO GetBuildingBDO(string buildingCode)
        {
            BuildingBDO buildingBDO = null;

            try {
                using (var DCEnt = new DCFIEntities())
                {
                    Building bldg = (from b in DCEnt.Buildings
                                     where b.BuildingCode == buildingCode
                                     select b).FirstOrDefault();
                    if (bldg != null)
                    {
                        buildingBDO = new BuildingBDO();
                        ConvertBuildingToBuildingBDO(bldg, buildingBDO);
                    }
                }
            }catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }
            return(buildingBDO);
        }
Exemplo n.º 2
0
        public bool UpdateBuilding(ref Building building, ref string message)
        {
            BuildingBDO bbdo = new BuildingBDO();

            TranslateBuildingToBuildingBDO(building, bbdo);
            return(blogic.UpdateBuilding(ref bbdo, ref message));
        }
Exemplo n.º 3
0
 public void TranslateBuildingBDOToBuildingDTO(BuildingBDO bBDO, Building bldg)
 {
     bldg.BuildingCode = bBDO.BuildingCode;
     bldg.BuildingName = bBDO.BuildingName;
     bldg.Deactivated  = bBDO.Deactivated;
     bldg.Description  = bBDO.Description;
     bldg.Rooms        = ToRoomDTO(bBDO.Rooms);
 }
Exemplo n.º 4
0
 public void TranslateBuildingToBuildingBDO(Building b, BuildingBDO bbdo)
 {
     bbdo.BuildingCode = b.BuildingCode;
     bbdo.BuildingName = b.BuildingName;
     bbdo.Deactivated  = b.Deactivated;
     bbdo.Description  = b.Description;
     bbdo.Rooms        = ToRoomBDOList(b.Rooms);
 }
Exemplo n.º 5
0
 private void ConvertBuildingBDOToBuilding(BuildingBDO bdo, Building b)
 {
     b.BuildingCode = bdo.BuildingCode;
     b.BuildingName = bdo.BuildingName;
     b.Deactivated  = bdo.Deactivated;
     b.Description  = bdo.Description;
     b.Rooms        = ToRoomList(bdo.Rooms);
 }
Exemplo n.º 6
0
 private void ConvertBuildingToBuildingBDO(Building b, BuildingBDO bdo)
 {
     bdo.BuildingCode = b.BuildingCode;
     bdo.BuildingName = b.BuildingName;
     bdo.Deactivated  = b.Deactivated;
     bdo.Description  = b.Description;
     //bdo.Rooms = ToRoomBDOList(b.Rooms);
 }
Exemplo n.º 7
0
        public BuildingBDO GetBuilding(string buildingCode)
        {
            BuildingBDO b = new BuildingBDO();

            b = bdao.GetBuildingBDO(buildingCode);
            if (b != null)
            {
                b.Rooms = bdao.GetAllRoomsForBuilding(b.BuildingCode);
            }
            return(b);
        }
Exemplo n.º 8
0
        public Building GetBuilding(string buildingCode, ref string message)
        {
            Building    bldg = new Building();
            BuildingBDO bbdo = blogic.GetBuilding(buildingCode);

            if (bbdo != null)
            {
                TranslateBuildingBDOToBuildingDTO(bbdo, bldg);
            }
            else
            {
                message = "Building Does Not Exists";
            }

            return(bldg);
        }
Exemplo n.º 9
0
        public List <BuildingBDO> GetAllBuildings()
        {
            List <Building> bList = new List <Building>();

            using (var DCEnt = new DCFIEntities())
            {
                var allBuildings = (DCEnt.Buildings);
                bList = allBuildings.ToList <Building>();
            }

            List <BuildingBDO> bBDOList = new List <BuildingBDO>();

            foreach (Building b in bList)
            {
                BuildingBDO bBDO = new BuildingBDO();
                ConvertBuildingToBuildingBDO(b, bBDO);
                bBDOList.Add(bBDO);
            }
            return(bBDOList);
        }
Exemplo n.º 10
0
        public Boolean CreateBuilding(ref BuildingBDO buildBDO, ref string message)
        {
            message = "Building Added Successfully";
            bool ret = true;

            Building b = new Building();

            ConvertBuildingBDOToBuilding(buildBDO, b);
            using (var DCEnt = new DCFIEntities())
            {
                DCEnt.Buildings.Add(b);
                DCEnt.Entry(b).State = System.Data.Entity.EntityState.Added;
                int num = DCEnt.SaveChanges();
                buildBDO.BuildingCode = b.BuildingCode;

                if (num != 1)
                {
                    ret     = false;
                    message = "Adding of Building failed";
                }
            }
            return(ret);
        }
Exemplo n.º 11
0
        public Boolean CreateBuilding(ref BuildingBDO buildBDO, ref string message)
        {
            message = "Building Added Successfully";
            bool ret = true;

            try {
                Building b = new Building();
                ConvertBuildingBDOToBuilding(buildBDO, b);
                using (var DCEnt = new DCFIEntities())
                {
                    DCEnt.Buildings.Add(b);
                    DCEnt.Entry(b).State = System.Data.Entity.EntityState.Added;
                    int num = DCEnt.SaveChanges();
                    buildBDO.BuildingCode = b.BuildingCode;

                    if (num < 1)
                    {
                        ret     = false;
                        message = "Adding of Building failed";
                    }
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }
            return(ret);
        }
Exemplo n.º 12
0
        public List <BuildingBDO> GetAllBuildings()
        {
            List <BuildingBDO> bBDOList = new List <BuildingBDO>();
            List <Building>    bList    = new List <Building>();

            try
            {
                using (var DCEnt = new DCFIEntities())
                {
                    var allBuildings = (DCEnt.Buildings);
                    bList = allBuildings.ToList <Building>();



                    foreach (Building b in bList)
                    {
                        BuildingBDO bBDO = new BuildingBDO();
                        ConvertBuildingToBuildingBDO(b, bBDO);
                        bBDOList.Add(bBDO);
                    }
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }
            return(bBDOList);
        }
Exemplo n.º 13
0
 public bool UpdateBuilding(ref BuildingBDO building, ref string message)
 {
     return(bdao.UpdateBuilding(ref building, ref message));
 }
Exemplo n.º 14
0
        public Boolean UpdateBuilding(ref BuildingBDO buildBDO, ref string message)
        {
            message = "Building updated successfully.";
            Boolean  ret = true;
            Building b   = new Building();

            ConvertBuildingBDOToBuilding(buildBDO, b);
            Building buildingInDB = new Building();

            using (var DCEnt = new DCFIEntities())
            {
                var buildingCode = buildBDO.BuildingCode;
                buildingInDB = (from bee in DCEnt.Buildings
                                where bee.BuildingCode == buildingCode
                                select bee).FirstOrDefault();
                if (buildingInDB == null)
                {
                    throw new Exception("No Building with BuildingCode " + buildBDO.BuildingCode);
                }

                // 1st Part
                if (buildingInDB.Rooms.Count == 0)
                {
                    foreach (Room rm in b.Rooms)
                    {
                        buildingInDB.Rooms.Add(rm);
                    }
                }
                else if (buildingInDB.Rooms.Count < b.Rooms.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable <Room> rmToAdd = b.Rooms.Except(buildingInDB.Rooms);
                    if (rmToAdd != null)
                    {
                        foreach (Room child in rmToAdd)
                        {
                            buildingInDB.Rooms.Add(child);
                        }
                    }

                    IEnumerable <Room> rmToRemove = buildingInDB.Rooms.Except(b.Rooms);
                    if (rmToRemove != null)
                    {
                        foreach (Room child in rmToRemove)
                        {
                            buildingInDB.Rooms.Add(child);
                        }
                    }
                }
                else if (buildingInDB.Rooms.Count > b.Rooms.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable <Room> rmToAdd = b.Rooms.Except(buildingInDB.Rooms);
                    if (rmToAdd != null)
                    {
                        foreach (Room child in rmToAdd)
                        {
                            buildingInDB.Rooms.Add(child);
                        }
                    }


                    // TBC
                    IEnumerable <Room> rmToRemove = buildingInDB.Rooms.Except(b.Rooms);
                    if (rmToRemove != null)
                    {
                        foreach (Room child in rmToRemove)
                        {
                            buildingInDB.Rooms.Add(child);
                        }
                    }
                }
                else if (buildingInDB.Rooms.Count == b.Rooms.Count)
                {
                    //compare 2 lists check the non existing to the other
                    IEnumerable <Room> rmToAdd = b.Rooms.Except(buildingInDB.Rooms);
                    if (rmToAdd != null)
                    {
                        foreach (Room child in rmToAdd)
                        {
                            buildingInDB.Rooms.Add(child);
                        }
                    }

                    IEnumerable <Room> rmToRemove = buildingInDB.Rooms.Except(b.Rooms);
                    if (rmToRemove != null)
                    {
                        foreach (Room child in rmToRemove)
                        {
                            buildingInDB.Rooms.Add(child);
                        }
                    }
                }
            }
            using (var DC = new DCFIEntities())
            {
                buildingInDB = b;

                DC.Entry(buildingInDB).State = System.Data.Entity.EntityState.Modified;
                foreach (Room r in buildingInDB.Rooms)
                {
                    DC.Entry(r).State = r.RoomId == 0 ? System.Data.Entity.EntityState.Added : System.Data.Entity.EntityState.Modified;
                }
                int num = DC.SaveChanges();

                if (num > 0)
                {
                    //  ret = false;
                    message = "No building is updated.";
                }
            }

            return(ret);
        }
Exemplo n.º 15
0
        public Boolean UpdateBuilding(ref BuildingBDO buildBDO, ref string message)
        {
            message = "Building updated successfully.";
            Boolean     ret = true;
            List <Room> toRemove;
            List <Room> toAdd;
            List <Room> toUpdate;
            Building    b = new Building();

            try {
                ConvertBuildingBDOToBuilding(buildBDO, b);
                Building buildingInDB = new Building();
                using (var DCEnt = new DCFIEntities())
                {
                    var buildingCode = buildBDO.BuildingCode;
                    buildingInDB = (from bee in DCEnt.Buildings
                                    where bee.BuildingCode == buildingCode
                                    select bee).FirstOrDefault();
                    if (buildingInDB == null)
                    {
                        throw new Exception("No Building with BuildingCode " + buildBDO.BuildingCode);
                    }


                    // 1st Part
                    if (buildingInDB.Rooms.Count == 0)
                    {
                        foreach (Room rm in b.Rooms)
                        {
                            buildingInDB.Rooms.Add(rm);
                        }
                    }
                    else
                    {
                        toRemove = new List <Room>();
                        toAdd    = new List <Room>();
                        toUpdate = new List <Room>();
                        if (buildingInDB.Rooms.Count < b.Rooms.Count)
                        {
                            foreach (Room r in b.Rooms)
                            {
                                List <Room> rIn = buildingInDB.Rooms.Where(ro => ro.RoomCode == r.RoomCode).ToList <Room>();
                                if (rIn.Count == 0)
                                {
                                    toAdd.Add(r);
                                }
                            }
                            foreach (Room r in buildingInDB.Rooms)
                            {
                                int co = b.Rooms.Where(ro => ro.RoomCode == r.RoomCode).Count();
                                if (co == 0)
                                {
                                    toRemove.Add(r);
                                }
                            }
                        }
                        else if (buildingInDB.Rooms.Count > b.Rooms.Count)
                        {
                            foreach (Room r in b.Rooms)
                            {
                                List <Room> rIn = buildingInDB.Rooms.Where(ro => ro.RoomCode == r.RoomCode).ToList <Room>();
                                if (rIn.Count == 0)
                                {
                                    toAdd.Add(r);
                                }
                            }
                            foreach (Room r in buildingInDB.Rooms)
                            {
                                int co = b.Rooms.Where(ro => ro.RoomCode == r.RoomCode).Count();
                                if (co == 0)
                                {
                                    toRemove.Add(r);
                                }
                            }
                        }
                        else if (buildingInDB.Rooms.Count == b.Rooms.Count)
                        {
                            foreach (Room r in b.Rooms)
                            {
                                List <Room> rIn = buildingInDB.Rooms.Where(ro => ro.RoomCode == r.RoomCode).ToList <Room>();
                                if (rIn.Count == 0)
                                {
                                    toAdd.Add(r);
                                }
                            }
                            foreach (Room r in buildingInDB.Rooms)
                            {
                                int co = b.Rooms.Where(ro => ro.RoomCode == r.RoomCode).Count();
                                if (co == 0)
                                {
                                    toRemove.Add(r);
                                }
                            }
                        }

                        foreach (Room r in b.Rooms)
                        {
                            List <Room> rIn = buildingInDB.Rooms.Where(ro => ro.RoomCode == r.RoomCode).ToList <Room>();

                            if (rIn.Exists(p => p.RoomCode == r.RoomCode))
                            {
                                if (!CompareRoom(rIn[0], r))
                                {
                                    toUpdate.Add(r);
                                }
                            }
                        }

                        foreach (Room r in toAdd)
                        {
                            buildingInDB.Rooms.Add(r);
                        }

                        foreach (Room r in toRemove)
                        {
                            DCEnt.Rooms.Remove(r);
                            DCEnt.Entry(r).State = System.Data.Entity.EntityState.Deleted;
                        }

                        foreach (Room r in toUpdate)
                        {
                            var roomIn = (from rm in DCEnt.Rooms
                                          where rm.RoomId == r.RoomId
                                          select rm).FirstOrDefault <Room>();

                            DCEnt.Rooms.Remove(roomIn);

                            roomIn.BuildingCode = r.BuildingCode;
                            roomIn.Capacity     = r.Capacity;
                            roomIn.Deactivated  = r.Deactivated;
                            roomIn.Description  = r.Description;
                            roomIn.RoomCode     = r.RoomCode;
                            roomIn.RoomNumber   = r.RoomNumber;
                            roomIn.RoomId       = r.RoomId;

                            DCEnt.Rooms.Attach(roomIn);
                            DCEnt.Entry(roomIn).State = System.Data.Entity.EntityState.Modified;
                        }
                    }
                    if (CompareBuilding(buildingInDB, b))
                    {
                        DCEnt.SaveChanges();                                                                                                                                          //    DCEnt.Entry(r).State = System.Data.Entity.EntityState.Modified;
                    }
                    else
                    {
                        buildingInDB.BuildingCode = b.BuildingCode;
                        buildingInDB.BuildingName = b.BuildingName;
                        buildingInDB.Description  = b.Description;

                        DCEnt.Entry(buildingInDB).State = System.Data.Entity.EntityState.Modified;
                        DCEnt.SaveChanges();
                    }
                }
            }
            catch (DbEntityValidationException dbEx)
            {
                foreach (var validationErrors in dbEx.EntityValidationErrors)
                {
                    foreach (var validationError in validationErrors.ValidationErrors)
                    {
                        Trace.TraceInformation("Property: {0} Error: {1}",
                                               validationError.PropertyName,
                                               validationError.ErrorMessage);
                    }
                }
            }
            return(ret);
        }