Exemple #1
0
        private CommunityEventItem SaveDiaryItem(Int32 idCommunity, long idItem, CommunityEventItem dto, String description, String descriptionPlain)
        {
            CommunityEventItem previousItem = null;
            CommunityEventItem savedItem    = null;
            bool NotifyEdit = false;

            if (dto.StartDate > dto.EndDate)
            {
                dto.EndDate = (dto.ShowDateInfo ? dto.StartDate : dto.StartDate.AddHours(2));
            }
            DateTime oldStartDate = dto.StartDate;
            DateTime oldEndDate   = dto.EndDate;

            if (idItem == 0)
            {
                dto.Id = 0;
            }
            else
            {
                dto.Id       = idItem;
                previousItem = Service.EventItemGet(idItem);
                if (previousItem != null)
                {
                    oldStartDate = previousItem.StartDate;
                    oldEndDate   = previousItem.EndDate;
                }
                NotifyEdit = previousItem.Note != dto.Note || Service.EventItemGetDescription(previousItem) != description || previousItem.Title != dto.Title || previousItem.StartDate != dto.StartDate || previousItem.EndDate != dto.EndDate || previousItem.Place != dto.Place || previousItem.Link != dto.Link;
            }
            CommunityEventType type = Service.GetDiaryEventType();

            return(Service.SaveEventItem(idCommunity, dto, description, descriptionPlain, UserContext.CurrentUser.Id, UserContext.CurrentUser.Id, type));
        }
Exemple #2
0
        public void SaveItem(Int32 idCommunity, long idItem, CommunityEventItem dto, DateTime startDate, DateTime endDate, List <dtoWeekDay> weekDays, String description, String descriptionPlain)
        {
            if (UserContext.isAnonymous)
            {
                View.DisplaySessionTimeout(idCommunity, idItem);
            }
            else
            {
                CommunityEventType type     = Service.GetDiaryEventType();
                CommunityEvent     eventObj = Service.AddMultipleItems(idCommunity, dto, description, descriptionPlain, UserContext.CurrentUserID, type, startDate, endDate, weekDays);

                if (eventObj == null)
                {
                    View.SetBackToDiary(idCommunity, 0);
                }
                else if (eventObj.Items != null && eventObj.Items.Count > 0)
                {
                    View.SendToItemsList(idCommunity, eventObj.Items.FirstOrDefault().Id);
                }
                else
                {
                    View.SetBackToDiary(idCommunity, 0);
                }
            }
        }
Exemple #3
0
        public Boolean PhisicalDeleteCommunityDiary(Int32 idCommunity, String baseFilePath, String baseThumbnailPath)
        {
            Boolean deleted = false;

            try
            {
                CommunityEventType eventType = GetDiaryEventType();
                Manager.BeginTransaction();
                List <String> filesToRemove = new List <String>();

                List <CommunityEvent> diaryEvents = (from e in Manager.GetIQ <CommunityEvent>() where e.IdCommunityOwner == idCommunity && e.EventType == eventType && e.AllowEdit == true select e).ToList();
                List <long>           idEvents    = diaryEvents.Select(i => i.Id).ToList();
                List <EventItemFile>  items       = null;
                if (idEvents.Count <= maxItemsForQuery)
                {
                    items = (from f in Manager.GetIQ <EventItemFile>() where f.IdCommunity == idCommunity && idEvents.Contains(f.IdEventOwner) select f).ToList();
                }
                else
                {
                    items = (from f in Manager.GetIQ <EventItemFile>() where f.IdCommunity == idCommunity select f).ToList().Where(f => idEvents.Contains(f.IdEventOwner)).ToList();
                }
                List <liteModuleLink> links = (from f in items where f.Link != null && !f.Item.IsInternal select f.Link).ToList();
                if (items.Any())
                {
                    foreach (EventItemFile attachment in items.Where(i => i.Item.IsInternal))
                    {
                        filesToRemove.Add(ServiceRepository.GetItemDiskFullPath(baseFilePath, attachment.Item));
                        filesToRemove.Add(ServiceRepository.GetItemThumbnailFullPath(baseThumbnailPath, attachment.Item));
                        Manager.DeletePhysical(attachment.Link);
                        Manager.DeletePhysical(attachment.Item);
                        if (attachment.Version != null)
                        {
                            Manager.DeletePhysical(attachment.Version);
                        }
                    }
                    if (links.Any())
                    {
                        Manager.DeletePhysicalList(links);
                    }
                    Manager.DeletePhysicalList(items);
                }
                else if (links.Any())
                {
                    Manager.DeletePhysicalList(links);
                }
                if (diaryEvents.Any())
                {
                    Manager.DeletePhysicalList(diaryEvents);
                }

                Manager.Commit();
                Delete.Files(filesToRemove);
            }
            catch (Exception ex)
            {
                Manager.RollBack();
            }
            return(deleted);
        }
Exemple #4
0
        public List <dtoDiaryItem> GetDtoDiaryItems(int idCommunity, Boolean ascendingLesson, ModuleCommunityDiary module, lm.Comol.Core.FileRepository.Domain.ModuleRepository moduleRepository, Boolean allVisibleItems, List <lm.Comol.Core.DomainModel.Repository.RepositoryAttachmentUploadActions> actions, lm.Comol.Core.DomainModel.Repository.RepositoryAttachmentUploadActions dAction, String unknownUser)
        {
            List <dtoDiaryItem> items     = new List <dtoDiaryItem>();
            litePerson          person    = Manager.GetLitePerson(UC.CurrentUserID);
            CommunityEventType  eventType = GetDiaryEventType();

            if (idCommunity > 0 && person != null)
            {
                int lessnoNumber = 1;
                items = (from item in CommunityEventItemsQuery(idCommunity, eventType, person, allVisibleItems).ToList()
                         select CreateDtoDiaryItem(person, item, allVisibleItems, module, moduleRepository, ref lessnoNumber, actions, dAction, unknownUser)).ToList();
                if (!ascendingLesson)
                {
                    items = items.OrderByDescending(i => i.LessonNumber).ToList();
                }
            }
            return(items);
        }
Exemple #5
0
        public List <CommunityEventItem> GetDiaryItems(Int32 idCommunity, litePerson person, Boolean allVisibleItems)
        {
            CommunityEventType eventType = GetDiaryEventType();

            return(CommunityEventItemsQuery(idCommunity, eventType, person, allVisibleItems).ToList());
        }
        protected IEnumerable <CommunityEventItem> CommunityEventItemsQuery(Int32 idCommunity, CommunityEventType eventType, litePerson person, Boolean allVisibleItems)
        {
            IEnumerable <CommunityEventItem> query = (from item in Manager.GetAll <CommunityEventItem>(i => i.IdCommunityOwner == idCommunity && i.EventOwner != null && i.EventOwner.EventType == eventType &&
                                                                                                       (allVisibleItems || (i.IsVisible || (!i.IsVisible && i.Owner != null && i.Owner.Id == person.Id))))
                                                      orderby item.StartDate, item.CreatedOn
                                                      select item);

            return(query);
        }
        public CommunityEventItem SaveEventItem(int idCommunity, CommunityEventItem unsavedItem, String description, String descriptionPlain, int ownerId, int savedById, CommunityEventType eventType)
        {
            CommunityEventItem eventItem = null;

            litePerson     owner      = Manager.GetLitePerson(ownerId);
            litePerson     savedBy    = Manager.GetLitePerson(savedById);
            liteCommunity  community  = Manager.GetLiteCommunity(idCommunity);
            CommunityEvent eventOwner = unsavedItem.EventOwner;

            try
            {
                if (owner != null && savedBy != null && (community != null && idCommunity > 0))
                {
                    Manager.BeginTransaction();
                    if (unsavedItem.Id == 0)
                    {
                        eventItem                  = new CommunityEventItem();
                        eventItem.Owner            = owner;
                        eventItem.CreatedBy        = savedBy;
                        eventItem.CreatedOn        = DateTime.Now;
                        eventItem.ModifiedBy       = savedBy;
                        eventItem.ModifiedOn       = eventItem.CreatedOn;
                        eventItem.IdCommunityOwner = idCommunity;
                        eventItem.AllowEdit        = true;
                    }
                    else
                    {
                        eventItem = Manager.Get <CommunityEventItem>(unsavedItem.Id);
                        if (eventItem.Owner == null)
                        {
                            eventItem.Owner = savedBy;
                        }
                        eventItem.ModifiedBy = savedBy;
                        eventItem.ModifiedOn = DateTime.Now;
                    }
                    eventItem.Note         = unsavedItem.Note;
                    eventItem.NotePlain    = unsavedItem.NotePlain;
                    eventItem.Place        = unsavedItem.Place;
                    eventItem.Title        = unsavedItem.Title;
                    eventItem.StartDate    = unsavedItem.StartDate;
                    eventItem.EndDate      = unsavedItem.EndDate;
                    eventItem.ShowDateInfo = unsavedItem.ShowDateInfo;
                    eventItem.IsVisible    = unsavedItem.IsVisible;
                    eventItem.Link         = unsavedItem.Link;

                    if (unsavedItem.Id == 0)
                    {
                        eventOwner = CreateGenericEvent(idCommunity, eventItem, eventType, savedBy);
                        Manager.SaveOrUpdate(eventOwner);
                        eventItem.EventOwner = eventOwner;
                        if (eventOwner.Items == null)
                        {
                            eventOwner.Items = new List <CommunityEventItem>();
                        }
                        eventOwner.Items.Add(eventItem);
                        Manager.SaveOrUpdate(eventItem);
                        Manager.SaveOrUpdate(eventOwner);
                    }
                    else
                    {
                        Manager.SaveOrUpdate(eventItem);
                    }

                    DescriptionEventItem descriptionItem = Manager.Get <DescriptionEventItem>(eventItem.Id);
                    if (descriptionItem == null && !string.IsNullOrEmpty(description))
                    {
                        descriptionItem = new DescriptionEventItem()
                        {
                            Id = eventItem.Id
                        }
                    }
                    ;
                    if (descriptionItem != null)
                    {
                        descriptionItem.Description      = description;
                        descriptionItem.DescriptionPlain = descriptionPlain;
                        Manager.SaveOrUpdate(descriptionItem);
                    }
                    Manager.Commit();
                }
            }
            catch (Exception ex)
            {
                Manager.RollBack();
                eventItem = null;
            }

            return(eventItem);
        }
        public CommunityEvent AddMultipleItems(Int32 idCommunity, CommunityEventItem dtoItem, String description, String descriptionPlain, int ownerId, CommunityEventType eventType, DateTime startDate, DateTime endDate, List <dtoWeekDay> weekDays)
        {
            CommunityEvent communityEvent = null;

            try
            {
                litePerson    person    = Manager.GetLitePerson(ownerId);
                liteCommunity community = Manager.GetLiteCommunity(idCommunity);
                if ((community != null && idCommunity > 0) && person != null)
                {
                    List <dtoWeekDayRecurrence> itemsToInsert = dtoWeekDayRecurrence.CreateRecurrency(startDate, endDate, weekDays);
                    if (itemsToInsert.Count > 0)
                    {
                        Manager.BeginTransaction();
                        communityEvent = CreateGenericEvent(idCommunity, dtoItem, eventType, person);
                        Manager.SaveOrUpdate(communityEvent);
                        foreach (dtoWeekDayRecurrence recurrence in itemsToInsert)
                        {
                            CommunityEventItem eventItem = new CommunityEventItem()
                            {
                                IdCommunityOwner = idCommunity, EventOwner = communityEvent, Owner = person, CreatedBy = person, CreatedOn = DateTime.Now
                            };
                            eventItem.ModifiedBy   = eventItem.CreatedBy;
                            eventItem.ModifiedOn   = eventItem.CreatedOn;
                            eventItem.Note         = dtoItem.Note;
                            eventItem.NotePlain    = dtoItem.NotePlain;
                            eventItem.Place        = dtoItem.Place;
                            eventItem.Title        = dtoItem.Title;
                            eventItem.StartDate    = recurrence.StartDate;
                            eventItem.EndDate      = recurrence.EndDate;
                            eventItem.ShowDateInfo = dtoItem.ShowDateInfo;
                            eventItem.IsVisible    = dtoItem.IsVisible;
                            eventItem.Link         = dtoItem.Link;
                            eventItem.AllowEdit    = true;
                            Manager.SaveOrUpdate(eventItem);
                            if (!String.IsNullOrEmpty(description))
                            {
                                DescriptionEventItem descriptionItem = new DescriptionEventItem()
                                {
                                    Id = eventItem.Id, Description = description
                                };
                                descriptionItem.DescriptionPlain = descriptionPlain;
                                Manager.SaveOrUpdate(descriptionItem);
                            }
                            communityEvent.Items.Add(eventItem);
                        }
                        Manager.SaveOrUpdate(communityEvent);
                        Manager.Commit();
                    }
                }
            }
            catch (Exception ex)
            {
                Manager.RollBack();
                communityEvent = null;
            }
            return(communityEvent);
        }
        private CommunityEvent CreateGenericEvent(Int32 idCommunity, CommunityEventItem item, CommunityEventType eventType, litePerson person)
        {
            CommunityEvent oEventItem = new CommunityEvent();

            oEventItem.IdCommunityOwner = idCommunity;
            oEventItem.ForEver          = false;
            oEventItem.IsMacro          = false;
            oEventItem.IsRepeat         = false;
            oEventItem.IsVisible        = item.IsVisible;
            oEventItem.Items            = new List <CommunityEventItem>();
            oEventItem.Link             = item.Link;

            if (item.ModifiedOn.Equals(DateTime.MinValue))
            {
                oEventItem.ModifiedOn = DateTime.Now;
                item.ModifiedOn       = oEventItem.ModifiedOn;
            }
            else
            {
                oEventItem.ModifiedOn = item.ModifiedOn;
            }
            oEventItem.Name = "";
            ////DiaryItem.Title
            oEventItem.Note      = item.Note;
            oEventItem.NotePlain = item.NotePlain;
            oEventItem.Owner     = person;
            oEventItem.Place     = item.Place;
            oEventItem.Year      = item.StartDate.Year;
            oEventItem.EventType = eventType;
            if (item.StartDate.Month < 9)
            {
                oEventItem.Year = oEventItem.Year - 1;
            }
            return(oEventItem);
        }