Beispiel #1
0
        public BuildingSite AddNewSite(int userID, string siteName, string siteAddress, string image64)
        {
            BuildingSite site   = null;
            string       imgRef = uploadImg(image64);

            try
            {
                var result = Dal.AddNewSite(userID, siteName, siteAddress, imgRef);

                if (result == null)
                {
                    return(null);
                }


                site = new BuildingSite
                {
                    SiteId       = int.Parse(result.Rows[0]["siteID"].ToString()),
                    SiteName     = result.Rows[0]["siteName"].ToString(),
                    SiteAddress  = result.Rows[0]["siteAddress"].ToString(),
                    SiteStatus   = bool.Parse(result.Rows[0]["siteStatus"].ToString()),
                    UserTypeId   = int.Parse(result.Rows[0]["userTypeID"].ToString()),
                    UserTypeName = result.Rows[0]["userTypName"].ToString(),
                    SiteImage    = imgRef,
                    Rooms        = new List <Room>()
                };
                return(site);
            }


            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Beispiel #2
0
        public List <BuildingSite> GetUserSites(int userId)
        {
            var results = Dal.GetUserSites(userId);

            var sites = new List <BuildingSite>();

            if (results == null)
            {
                return(sites);
            }

            for (var i = 0; i < results.Rows.Count; i++)
            {
                var staticsSite = Dal.GetStaticsOnSite(int.Parse(results.Rows[i]["siteID"].ToString()));
                var site        = new BuildingSite
                {
                    SiteId        = int.Parse(results.Rows[i]["siteID"].ToString()),
                    SiteName      = results.Rows[i]["siteName"].ToString(),
                    SiteAddress   = results.Rows[i]["siteAddress"].ToString(),
                    SiteStatus    = bool.Parse(results.Rows[i]["siteStatus"].ToString()),
                    UserTypeId    = int.Parse(results.Rows[i]["userTypeID"].ToString()),
                    UserTypeName  = results.Rows[i]["userTypName"].ToString(),
                    SiteImage     = results.Rows[i]["img"].ToString(),
                    SumUserInSite = int.Parse(staticsSite.Rows[0]["sumOfUser"].ToString()),
                    SumRoomInSite = int.Parse(staticsSite.Rows[0]["sumOfRooms"].ToString()),
                };
                sites.Add(site);
            }
            return(sites);
        }
Beispiel #3
0
        public List <BuildingSite> GetUserSites(int userId)
        {
            var results = Dal.GetUserSites(userId);
            var sites   = new List <BuildingSite>();

            if (results == null)
            {
                return(sites);
            }

            for (var i = 0; i < results.Rows.Count; i++)
            {
                var site = new BuildingSite
                {
                    SiteId       = int.Parse(results.Rows[i]["siteID"].ToString()),
                    SiteName     = results.Rows[i]["siteName"].ToString(),
                    SiteAddress  = results.Rows[i]["siteAddress"].ToString(),
                    SiteStatus   = bool.Parse(results.Rows[i]["siteStatus"].ToString()),
                    UserTypeId   = int.Parse(results.Rows[i]["userTypeID"].ToString()),
                    UserTypeName = results.Rows[i]["userTypName"].ToString()
                };
                sites.Add(site);
            }
            return(sites);
        }
Beispiel #4
0
        public UserInSite ConfirmInvite(int siteId, int senderId, int reciverId)
        {
            DataTable res = Dal.ConfirmInvite(siteId, senderId, reciverId);

            if (res == null)
            {
                return(null);
            }


            var site = new BuildingSite
            {
                SiteName     = res.Rows[0]["siteName"].ToString(),
                SiteId       = int.Parse(res.Rows[0]["SiteID"].ToString()),
                SiteAddress  = res.Rows[0]["SiteAddress"].ToString(),
                UserTypeId   = int.Parse(res.Rows[0]["userTypeID"].ToString()),
                UserTypeName = res.Rows[0]["userTypName"].ToString(),
                SiteStatus   = true
            };

            site.Rooms = getSiteRooms(siteId);

            var user = new User
            {
                Email     = res.Rows[0]["email"].ToString(),
                UserName  = res.Rows[0]["userName"].ToString(),
                FirstName = res.Rows[0]["firstName"].ToString(),
                LastName  = res.Rows[0]["lastName"].ToString(),
                Tel       = res.Rows[0]["tel"].ToString(),
                Img       = res.Rows[0]["img"].ToString(),
                UserId    = int.Parse(res.Rows[0]["userID"].ToString())
            };

            var userInSite = new UserInSite
            {
                user = user,
                Site = site
            };

            Notify(res.Rows[0]["OwnerEmail"].ToString(), "Invitation accepted", $"{user.FirstName} {user.LastName} has accepted your invite");

            return(userInSite);
        }
Beispiel #5
0
        public List <UserInSite> GetSentInvites(int userId)
        {
            var results = Dal.GetSentInvites(userId);

            if (results == null)
            {
                return(null);
            }
            List <UserInSite> InvitedUsers = new List <UserInSite>();

            for (int i = 0; i < results.Rows.Count; i++)
            {
                var user = new User
                {
                    UserId    = int.Parse(results.Rows[i]["userID"].ToString()),
                    UserName  = results.Rows[i]["userName"].ToString(),
                    FirstName = results.Rows[i]["firstName"].ToString(),
                    LastName  = results.Rows[i]["lastName"].ToString(),
                    Email     = results.Rows[i]["email"].ToString(),
                    Img       = results.Rows[i]["img"].ToString(),
                };

                var site = new BuildingSite
                {
                    SiteAddress  = results.Rows[i]["siteAddress"].ToString(),
                    SiteId       = int.Parse(results.Rows[i]["siteID"].ToString()),
                    SiteName     = results.Rows[i]["siteName"].ToString(),
                    UserTypeName = results.Rows[i]["userTypName"].ToString(),
                    UserTypeId   = int.Parse(results.Rows[i]["userTypeID"].ToString()),
                    SiteImage    = results.Rows[i]["img"].ToString()
                };
                InvitedUsers.Add(new UserInSite {
                    user = user, Site = site
                });
            }
            return(InvitedUsers);
        }
Beispiel #6
0
        public BuildingSite ChangeSiteStatus(int siteID, int statusID)
        {
            var result = Dal.ChangeSiteStatus(siteID, statusID);

            if (result == null)
            {
                return(null);
            }


            var site = new BuildingSite
            {
                SiteId       = int.Parse(result.Rows[0]["siteID"].ToString()),
                SiteName     = result.Rows[0]["siteName"].ToString(),
                SiteAddress  = result.Rows[0]["siteAddress"].ToString(),
                SiteStatus   = bool.Parse(result.Rows[0]["siteStatus"].ToString()),
                UserTypeId   = 0,
                UserTypeName = null,
                Rooms        = new List <Room>()
            };


            return(site);
        }
Beispiel #7
0
        public BuildingSite AddNewSite(int userID, string siteName, string siteAddress)
        {
            var result = Dal.AddNewSite(userID, siteName, siteAddress);

            if (result == null)
            {
                return(null);
            }


            var site = new BuildingSite
            {
                SiteId       = int.Parse(result.Rows[0]["siteID"].ToString()),
                SiteName     = result.Rows[0]["siteName"].ToString(),
                SiteAddress  = result.Rows[0]["siteAddress"].ToString(),
                SiteStatus   = bool.Parse(result.Rows[0]["siteStatus"].ToString()),
                UserTypeId   = int.Parse(result.Rows[0]["userTypeID"].ToString()),
                UserTypeName = result.Rows[0]["userTypName"].ToString(),
                Rooms        = new List <Room>()
            };


            return(site);
        }