コード例 #1
0
        public Result <Playground.Model.ViewModel.Playground> GetById(int playgroundID, int userID)
        {
            Result <Playground.Model.ViewModel.Playground> retVal = null;

            try
            {
                Playground.Model.Playground playground = Uow.Playgrounds.GetById(playgroundID);
                bool isOwner  = playground.OwnerID == userID;
                bool isMember = Uow.PlaygroundUsers.GetAll().Any(pgu => pgu.PlaygroundID == playgroundID && pgu.UserID == userID);

                Playground.Model.ViewModel.Playground playgorundVM = new Model.ViewModel.Playground()
                {
                    PlaygroundID = playground.PlaygroundID,
                    Address      = playground.Address,
                    Latitude     = playground.Latitude,
                    Longitude    = playground.Longitude,
                    Name         = playground.Name,
                    IsMember     = isMember,
                    IsOwner      = isOwner
                };

                retVal = ResultHandler <Playground.Model.ViewModel.Playground> .Sucess(playgorundVM);
            }
            catch (Exception ex)
            {
                log.Error("Error getting playground", ex);
                retVal = ResultHandler <Playground.Model.ViewModel.Playground> .Erorr("Error loading playgrond");
            }

            return(retVal);
        }
コード例 #2
0
        public Result <Playground.Model.Playground> AddPlayground(Playground.Model.Playground playground)
        {
            Result <Playground.Model.Playground> retVal = null;

            try
            {
                playground.CreationDate = DateTime.Now;
                Uow.Playgrounds.Add(playground);
                Uow.Commit();

                PlaygroundUser playgroundUser = new PlaygroundUser()
                {
                    UserID       = playground.OwnerID,
                    PlaygroundID = playground.PlaygroundID
                };
                AddUserToPlaygroound(playgroundUser);

                retVal = ResultHandler <Playground.Model.Playground> .Sucess(playground);
            }
            catch (Exception ex)
            {
                log.Error("Erorr adding playgorund", ex);
                retVal = ResultHandler <Playground.Model.Playground> .Erorr("Error adding playground");
            }

            return(retVal);
        }
コード例 #3
0
        public HttpResponseMessage UpdatePlayground(Playground.Model.Playground playground)
        {
            Result <Playground.Model.Playground> res = playgroundBusiness.UpdatePlayground(playground);

            HttpResponseMessage response = res.Success ?
                                           Request.CreateResponse(HttpStatusCode.Created, res.Data) :
                                           Request.CreateResponse(HttpStatusCode.InternalServerError, res.Message);

            return(response);
        }
コード例 #4
0
ファイル: UserBusiness.cs プロジェクト: doppler85/playground
        public Result <PagedResult <Playground.Model.ViewModel.PlaygroundUser> > FilterByPlayground(int page, int count, int playgroundID)
        {
            Result <PagedResult <Playground.Model.ViewModel.PlaygroundUser> > retVal = null;

            try
            {
                int totalItems = Uow.PlaygroundUsers
                                 .GetAll()
                                 .Where(u => u.PlaygroundID == playgroundID)
                                 .Count();

                page = GetPage(totalItems, page, count);

                Playground.Model.Playground playground = Uow.Playgrounds.GetById(playgroundID);

                List <Playground.Model.ViewModel.PlaygroundUser> users = Uow.PlaygroundUsers
                                                                         .GetAll()
                                                                         .Where(u => u.PlaygroundID == playgroundID)
                                                                         .Select(u => u.User)
                                                                         .OrderBy(u => u.FirstName)
                                                                         .ThenBy(u => u.LastName)
                                                                         .Skip((page - 1) * count)
                                                                         .Take(count)
                                                                         .Select(u => new Playground.Model.ViewModel.PlaygroundUser()
                {
                    UserID     = u.UserID,
                    FirstName  = u.FirstName,
                    LastName   = u.LastName,
                    PictureUrl = u.PictureUrl,
                    IsOwner    = u.UserID == playground.OwnerID
                })
                                                                         .ToList();

                PagedResult <Playground.Model.ViewModel.PlaygroundUser> result = new PagedResult <Playground.Model.ViewModel.PlaygroundUser>()
                {
                    CurrentPage = page,
                    TotalPages  = (totalItems + count - 1) / count,
                    TotalItems  = totalItems,
                    Items       = users
                };

                retVal = ResultHandler <PagedResult <Playground.Model.ViewModel.PlaygroundUser> > .Sucess(result);
            }
            catch (Exception ex)
            {
                log.Error(String.Format("Error loading users by playgorund. playgroundID: {0}", playgroundID), ex);
                retVal = ResultHandler <PagedResult <Playground.Model.ViewModel.PlaygroundUser> > .Erorr("Error loading users by playgorund");
            }

            return(retVal);
        }
コード例 #5
0
        public HttpResponseMessage AddPlayground(Playground.Model.Playground playground)
        {
            User currentUser = userBusiness.GetUserByExternalId(User.Identity.GetUserId()).Data;

            playground.OwnerID = currentUser.UserID;

            Result <Playground.Model.Playground> res = playgroundBusiness.AddPlayground(playground);

            HttpResponseMessage response = res.Success ?
                                           Request.CreateResponse(HttpStatusCode.Created, res.Data) :
                                           Request.CreateResponse(HttpStatusCode.InternalServerError, res.Message);

            return(response);
        }
コード例 #6
0
        public Result <Playground.Model.Playground> GetById(int playgroundID)
        {
            Result <Playground.Model.Playground> retVal = null;

            try
            {
                Playground.Model.Playground playground = Uow.Playgrounds.GetById(playgroundID);
                retVal = ResultHandler <Playground.Model.Playground> .Sucess(playground);
            }
            catch (Exception ex)
            {
                log.Error("Error getting playground", ex);
                retVal = ResultHandler <Playground.Model.Playground> .Erorr("Error loading playgrond");
            }

            return(retVal);
        }
コード例 #7
0
        public bool RemovePlayground(int playgroundID)
        {
            bool retVal = true;

            try
            {
                Playground.Model.Playground playgroundToDelete = Uow.Playgrounds.GetById(p => p.PlaygroundID == playgroundID);
                Uow.PlaygroundUsers.Delete(u => u.UserID == playgroundToDelete.OwnerID && u.PlaygroundID == playgroundID);
                Uow.Playgrounds.Delete(playgroundToDelete);
                Uow.Commit();
            }
            catch (Exception ex)
            {
                log.Error("Erorr deleting playgorund", ex);
                retVal = false;
            }
            return(retVal);
        }
コード例 #8
0
        public Result <Playground.Model.Playground> UpdatePlayground(Playground.Model.Playground playground)
        {
            Result <Playground.Model.Playground> retVal = null;

            try
            {
                Uow.Playgrounds.Update(playground, playground.PlaygroundID);
                Uow.Commit();

                retVal = ResultHandler <Playground.Model.Playground> .Sucess(playground);
            }
            catch (Exception ex)
            {
                log.Error("Error updating playground", ex);
                retVal = ResultHandler <Playground.Model.Playground> .Erorr("Error updating playground");
            }

            return(retVal);
        }