Exemplo n.º 1
0
        public InvestigationDTO AddInvestigation(InvestigationDTO detail, List <Guid> investigatorIDs, string appPath)
        {
            CrudFacadeBase <Investigation, Guid, InvestigationDTO, InvestigationDTO> crudFacadeBase = this;

            using (IUnitOfWork uow = crudFacadeBase.UnitOfWorkProvider.Create())
            {
                var entity = crudFacadeBase.Repository.InitializeNew();
                base.PopulateDetailToEntity(detail, entity);
                entity.Created = DateTime.Now;

                entity.ExportStats = StatsFacade.ExportStatsRepository.InitializeNew();
                if (!investigatorIDs.Contains(entity.OwnerID))
                {
                    investigatorIDs.Add(entity.OwnerID);
                }

                var investigators = this.UserFacade.Repository.GetByIds(investigatorIDs);

                foreach (var investigator in investigators)
                {
                    this.UserInvestigationRepository.Insert(new UserInvestigation()
                    {
                        Investigation = entity, User = investigator, LastAccess = (DateTime)SqlDateTime.MinValue
                    });
                }

                var result = base.Save(entity, true, detail, uow);
                CreateInvestigationFolder(result.Id, appPath);
                return(result);
            }
        }
Exemplo n.º 2
0
        public void UpdateLastAccess(Guid investigationId, string username)
        {
            CrudFacadeBase <Investigation, Guid, InvestigationDTO, InvestigationDTO> crudFacadeBase = this;

            using (IUnitOfWork uow = crudFacadeBase.UnitOfWorkProvider.Create())
            {
                var investigation = crudFacadeBase.Repository.GetById(investigationId);
                var user          = this.UserFacade.GetUser(username);
                var investigator  = investigation.UserInvestigations?.SingleOrDefault(u => u.UserId == user.Id);

                if (user.Role.Name == "Administrator" && investigator == null)
                {
                    investigator = this.UserInvestigationRepository.InitializeNew();
                    investigator.Investigation = investigation;
                    investigator.User          = this.UserFacade.Repository.GetById(user.Id);
                    investigator.LastAccess    = DateTime.Now.ToLocalTime();
                    this.UserInvestigationRepository.Insert(investigator);
                }
                else
                {
                    investigator            = this.UserInvestigationRepository.GetById(investigator.Id);
                    investigator.LastAccess = DateTime.UtcNow.ToLocalTime();
                    this.UserInvestigationRepository.Update(investigator);
                }
                uow.Commit();
            }
        }
Exemplo n.º 3
0
        public UserDTO GetOwner(Guid investigationId)
        {
            CrudFacadeBase <Investigation, Guid, InvestigationDTO, InvestigationDTO> crudFacadeBase = this;

            using (IUnitOfWork uow = crudFacadeBase.UnitOfWorkProvider.Create())
            {
                var investigation = crudFacadeBase.Repository.GetById(investigationId);
                var user          = this.UserFacade.Repository.GetById(investigation.OwnerID);
                return(AutoMapper.Mapper.Map <UserDTO>(user));
            }
        }
Exemplo n.º 4
0
        public UserDTO Save(UserDTO detail, string passwd)
        {
            CrudFacadeBase <User, Guid, UserDTO, UserDTO> crudFacadeBase = this;

            using (IUnitOfWork uow = crudFacadeBase.UnitOfWorkProvider.Create())
            {
                var entity = crudFacadeBase.Repository.InitializeNew();
                base.PopulateDetailToEntity(detail, entity);
                entity.Password = LoginFacade.SHA256Hash(passwd);
                return(base.Save(entity, true, detail, uow));
            }
        }
Exemplo n.º 5
0
        public void RemoveInvestigation(Guid id, string appPath)
        {
            this.RemoveInvestigationFolder(NetfoxWebSettings.Default.InvestigationPrefix + id, appPath);


            CrudFacadeBase <Investigation, Guid, InvestigationDTO, InvestigationDTO> crudFacadeBase = this;

            using (IUnitOfWork uow = crudFacadeBase.UnitOfWorkProvider.Create())
            {
                var entity = crudFacadeBase.Repository.GetById(id).ExportStats;
                uow.Commit();
                this.Repository.Delete(id);
                this.StatsFacade.ExportStatsRepository.Delete(entity.Id);
                uow.Commit();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Fills the data set using the query specified in the facade.
        /// </summary>
        public static void FillDataSet <TEntity, TKey, TListDTO, TDetailDTO>(this CrudFacadeBase <TEntity, TKey, TListDTO, TDetailDTO> facade, GridViewDataSet <TListDTO> dataSet)
            where TEntity : IEntity <TKey> where TDetailDTO : IEntity <TKey>
        {
            using (facade.UnitOfWorkProvider.Create())
            {
                facade.Query.Skip = dataSet.PageIndex * dataSet.PageSize;
                facade.Query.Take = dataSet.PageSize;
                facade.Query.SortCriteria.Clear();

                if (!string.IsNullOrEmpty(dataSet.SortExpression))
                {
                    facade.Query.AddSortCriteria(dataSet.SortExpression, dataSet.SortDescending ? SortDirection.Descending : SortDirection.Ascending);
                }

                dataSet.TotalItemsCount = facade.Query.GetTotalRowCount();
                dataSet.Items           = facade.Query.Execute();
            }
        }
Exemplo n.º 7
0
        public InvestigationDTO Save(InvestigationDTO detail, List <Guid> investigatorIDs)
        {
            CrudFacadeBase <Investigation, Guid, InvestigationDTO, InvestigationDTO> crudFacadeBase = this;

            using (IUnitOfWork uow = crudFacadeBase.UnitOfWorkProvider.Create())
            {
                var entity = crudFacadeBase.Repository.GetById(detail.Id);

                // Add owner - last access
                if (!investigatorIDs.Contains(detail.OwnerID))
                {
                    investigatorIDs.Add(detail.OwnerID);
                }
                // Add old owner - last access
                if (!investigatorIDs.Contains(entity.OwnerID))
                {
                    investigatorIDs.Add(entity.OwnerID);
                }

                base.PopulateDetailToEntity(detail, entity);

                var investigatorsList = new List <UserInvestigation>();
                foreach (var investigatorId in investigatorIDs)
                {
                    var item = entity.UserInvestigations.SingleOrDefault(i => i.UserId == investigatorId);

                    if (item != null)
                    {
                        item.User = this.UserFacade.Repository.GetById(investigatorId);
                    }
                    investigatorsList.Add(item ?? new UserInvestigation()
                    {
                        Investigation = entity, User = this.UserFacade.Repository.GetById(investigatorId), LastAccess = (DateTime)SqlDateTime.MinValue
                    });
                }
                entity.UserInvestigations = investigatorsList;
                return(base.Save(entity, false, detail, uow));
            }
        }