public async Task <Board> AddAnnouncement(Guid boardid, Announcement announcement)
        {
            DocumentDBRepository <Board> boardRepo = new DocumentDBRepository <Board>();

            Board board1 = await boardRepo.GetItemAsync(boardid);

            announcement.InitId();
            announcement.DateCreatedOn  = DateTime.UtcNow;
            announcement.DateModifiedOn = DateTime.UtcNow;

            board1.Announcements.Add(announcement);

            var result = await boardRepo.UpdateItemAsync(boardid, board1);

            return(result);
        }
        public async Task <Event> UpdateEvent(Event @event)
        {
            DocumentDBRepository <Event> eventRepo = new DocumentDBRepository <Event>();

            Event event1 = await eventRepo.GetItemAsync(@event.Id);


            event1.EventName    = @event.EventName;
            event1.EventBanner  = @event.EventBanner;
            event1.Description  = @event.Description;
            event1.ShowAsBanner = @event.ShowAsBanner;

            Event updatedEvent = await eventRepo.UpdateItemAsync(event1.Id, event1);

            return(updatedEvent);
        }
        public async Task <EventAggregateRoot> GetEventsByAnnouncmentID(Guid guid)
        {
            DocumentDBRepository <Event>     eventRepo = new DocumentDBRepository <Event>();
            ICollection <EventAggregateRoot> roots     = new List <EventAggregateRoot>();

            try
            {
                var events = await eventRepo.GetItemsAsync(x => x.Announcements.Any(y => y.Id == guid));

                return(new EventAggregateRoot(events.FirstOrDefault()));
            }
            catch (Exception m)
            {
                Console.WriteLine(m.Message);
                return(null);
            }
        }
        public async Task <BoardAggregateRoot> GetBoardsByAnnouncmentID(Guid guid)
        {
            DocumentDBRepository <Board>     boardRepo = new DocumentDBRepository <Board>();
            ICollection <BoardAggregateRoot> roots     = new List <BoardAggregateRoot>();

            try
            {
                var boards = await boardRepo.GetItemsAsync(x => x.Announcements.Any(y => y.Id == guid));

                return(new BoardAggregateRoot(boards.FirstOrDefault()));
            }
            catch (Exception m)
            {
                Console.WriteLine(m.Message);
                throw;
            }
        }
        public async Task <Event> AddContent(Guid event_guid, Guid announcement_guid, Content content)
        {
            DocumentDBRepository <Event>     eventRepo = new DocumentDBRepository <Event>();
            ICollection <EventAggregateRoot> roots     = new List <EventAggregateRoot>();

            try
            {
                var event1 = await eventRepo.GetItemAsync(event_guid);

                List <Announcement> updated_announcement = new List <Announcement>();

                foreach (var announcement in event1.Announcements)
                {
                    if (announcement.Id == announcement_guid)
                    {
                        List <Content> updated_content = announcement.Content.Append(new Content()
                        {
                            Description = content.Description, Id = Guid.NewGuid(), Image = content.Image, IsActive = content.IsActive, IsApproved = content.IsApproved, Posted = DateTime.Now, PostedBy = content.PostedBy, Title = content.Title
                        }).ToList();
                        updated_announcement.Add(new Announcement()
                        {
                            Content = updated_content, Description = announcement.Description, Id = announcement.Id, Img = announcement.Img, PostedDate = announcement.PostedDate, Title = announcement.Title
                        });
                    }
                    else
                    {
                        updated_announcement.Add(new Announcement()
                        {
                            Content = announcement.Content, Description = announcement.Description, Id = announcement.Id, Img = announcement.Img, PostedDate = announcement.PostedDate, Title = announcement.Title
                        });
                    }
                }

                event1.Announcements = updated_announcement;

                var res = eventRepo.UpdateItemAsync(event_guid, event1);

                return(await res);
            }
            catch (Exception m)
            {
                Console.WriteLine(m.Message);
                return(null);
            }
        }
Exemplo n.º 6
0
        public async Task <string> CheckIfUserExists(string email, string pno)
        {
            DocumentDBRepository <User> userRepo = new DocumentDBRepository <User>();
            var users = await userRepo.GetItemsAsync(x => x.Email == email || x.Pno.Equals(pno));

            foreach (var item in users)
            {
                if (item.Email == email)
                {
                    return("EMAIL_EXISTS");
                }
                else if (item.Pno.Equals(pno))
                {
                    return("PNO_EXISTS");
                }
            }
            return(null);
        }
        public async Task <IEnumerable <Board> > AddBoards(IEnumerable <Board> boards)
        {
            foreach (var board in boards)
            {
                board.InitId();
                board.DateCreatedOn  = DateTime.UtcNow;
                board.DateModifiedOn = DateTime.UtcNow;

                board.Announcements
                .ForEach(x => { x.InitId();
                                x.Content.ForEach(y => y.InitId()); });
            }

            DocumentDBRepository <Board> boardRepo = new DocumentDBRepository <Board>();
            var result = await boardRepo.CreateItemsAsync(boards);

            return(result);
        }
        public async Task <Board> UpdateBoard(Board board)
        {
            DocumentDBRepository <Board> boardRepo = new DocumentDBRepository <Board>();

            Board dbBoard = await boardRepo.GetItemAsync(board.Id);


            dbBoard.BoardName      = board.BoardName;
            dbBoard.BoardBanner    = board.BoardBanner;
            dbBoard.Description    = board.Description;
            dbBoard.ShowAsBanner   = board.ShowAsBanner;
            dbBoard.DateModifiedOn = DateTime.UtcNow;
            dbBoard.DateSchedule   = board.DateSchedule;
            dbBoard.IsFixed        = board.IsFixed;
            dbBoard.Order          = board.Order;

            Board updatedBoard = await boardRepo.UpdateItemAsync(dbBoard.Id, dbBoard);

            return(updatedBoard);
        }
        public async Task <Event> UpdateAnnouncement(Guid eventid, Announcement announcement)
        {
            DocumentDBRepository <Event> eventRepo = new DocumentDBRepository <Event>();
            IEnumerable <Event>          events    = new List <Event>();

            events = await eventRepo.GetItemsAsync(x => x.Id == eventid);

            Event to_be_updated_event = events.FirstOrDefault(x => x.Id == eventid);

            Announcement tobeUpdatedAnnouncement = to_be_updated_event.Announcements.FirstOrDefault(x => x.Id == announcement.Id);

            tobeUpdatedAnnouncement.Title       = announcement.Title;
            tobeUpdatedAnnouncement.PostedDate  = DateTime.Now;
            tobeUpdatedAnnouncement.Img         = announcement.Img;
            tobeUpdatedAnnouncement.Description = announcement.Description;

            to_be_updated_event.Announcements.FirstOrDefault(x => x.Id == announcement.Id).Equals(tobeUpdatedAnnouncement);
            Event updatedEvent = await eventRepo.UpdateItemAsync(to_be_updated_event.Id, to_be_updated_event);

            return(updatedEvent);
        }
        public async Task <IEnumerable <EventAggregateRoot> > GetAllEventRoots()
        {
            DocumentDBRepository <Event>     eventRepo = new DocumentDBRepository <Event>();
            ICollection <EventAggregateRoot> roots     = new List <EventAggregateRoot>();

            try
            {
                var events = await eventRepo.GetItemsAsync();

                foreach (var item in events)
                {
                    roots.Add(new EventAggregateRoot(item));
                }
                return(roots);
            }
            catch (Exception m)
            {
                List <EventAggregateRoot> noRootFound = new List <EventAggregateRoot>();
                Console.WriteLine(m.Message);
                return(noRootFound);
            }
        }
        public async Task DeleteBoard(Guid boardGuid)
        {
            DocumentDBRepository <Board> boardRepo = new DocumentDBRepository <Board>();

            await boardRepo.DeleteItemAsync(boardGuid);
        }