Exemple #1
0
 public List <KeyValuePair <Teacher, bool> > GetWorkShopTeacherModel(Guid congressId, Guid?workShopId)
 {
     try
     {
         var list             = new TeacherBO().Where(this.ConnectionHandler, x => x.CongressId == congressId);
         var getAllForArticle = new List <KeyValuePair <Teacher, bool> >();
         var guids            = new List <Guid>();
         if (workShopId.HasValue)
         {
             guids = new WorkShopTeacherBO().Select(ConnectionHandler, x => x.TeacherId,
                                                    x => x.WorkShopId == workShopId);
         }
         foreach (var teacher in list)
         {
             var added = guids.Any(x => x.Equals(teacher.Id));
             getAllForArticle.Add(new KeyValuePair <Teacher, bool>(teacher, added));
         }
         return(getAllForArticle);
     }
     catch (KnownException ex)
     {
         Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
         throw new KnownException(ex.Message, ex);
     }
     catch (Exception ex)
     {
         Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
         throw new KnownException(ex.Message, ex);
     }
 }
Exemple #2
0
 public override bool Delete(params object[] keys)
 {
     try
     {
         this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted);
         this.EnterpriseNodeConnection.StartTransaction(IsolationLevel.ReadUncommitted);
         this.FileManagerConnection.StartTransaction(IsolationLevel.ReadUncommitted);
         var obj = new TeacherBO().Get(this.ConnectionHandler, keys);
         var workShopTeacherBO = new WorkShopTeacherBO();
         var byFilter          = workShopTeacherBO.Where(ConnectionHandler, teacher => teacher.TeacherId == obj.Id);
         if (
             byFilter.Any(
                 workShopTeacher =>
                 !workShopTeacherBO.Delete(this.ConnectionHandler, workShopTeacher.WorkShopId,
                                           workShopTeacher.TeacherId)))
         {
             throw new Exception(Resources.Congress.ErrorInDeleteWorkShopTeacher);
         }
         if (!new TeacherBO().Delete(this.ConnectionHandler, keys))
         {
             throw new Exception(Resources.Congress.ErrorInSaveTeacher);
         }
         if (
             !EnterpriseNodeComponent.Instance.EnterpriseNodeTransactionalFacade(this.EnterpriseNodeConnection)
             .Delete(obj.Id))
         {
             return(false);
         }
         if (obj.ResumeAttachId.HasValue)
         {
             if (
                 !FileManagerComponent.Instance.FileTransactionalFacade(this.FileManagerConnection)
                 .Delete((Guid)obj.ResumeAttachId))
             {
                 throw new Exception(Resources.Congress.ErrorInDeleteResume);
             }
         }
         this.ConnectionHandler.CommitTransaction();
         this.EnterpriseNodeConnection.CommitTransaction();
         this.FileManagerConnection.CommitTransaction();
         return(true);
     }
     catch (KnownException ex)
     {
         this.ConnectionHandler.RollBack();
         this.EnterpriseNodeConnection.RollBack();
         this.FileManagerConnection.RollBack();
         Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
         throw new KnownException(ex.Message, ex);
     }
     catch (Exception ex)
     {
         this.ConnectionHandler.RollBack();
         this.EnterpriseNodeConnection.RollBack();
         this.FileManagerConnection.RollBack();
         Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
         throw new KnownException(ex.Message, ex);
     }
 }
        public override bool Delete(params object[] keys)
        {
            try
            {
                this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted);
                this.FileManagerConnection.StartTransaction(IsolationLevel.ReadUncommitted);
                var fileTransactionalFacade =
                    FileManagerComponent.Instance.FileTransactionalFacade(this.FileManagerConnection);
                var obj = new WorkShopBO().Get(this.ConnectionHandler, keys);
                var workShopTeacherBO = new WorkShopTeacherBO();
                var list = workShopTeacherBO.Where(this.ConnectionHandler,
                                                   teacher => teacher.WorkShopId == obj.Id);
                if (list.Any(guid => !workShopTeacherBO.Delete(this.ConnectionHandler, guid.WorkShopId, guid.TeacherId)))
                {
                    throw new Exception(Resources.Congress.ErrorInDeleteWorkShopTeacher);
                }
                if (!new WorkShopBO().Delete(this.ConnectionHandler, keys))
                {
                    throw new Exception(Resources.Congress.ErrorInDeleteWorkShop);
                }
                if (obj.ProgramAttachId != null)
                {
                    if (!fileTransactionalFacade.Delete(obj.ProgramAttachId))
                    {
                        throw new Exception(Resources.Congress.ErrorInDeleteWorkShopprogramFile);
                    }
                }
                if (obj.FileAttachId != null)
                {
                    if (!fileTransactionalFacade.Delete(obj.FileAttachId))
                    {
                        throw new Exception(Resources.Congress.ErrorInEditWorkShopAttachFile);
                    }
                }

                this.ConnectionHandler.CommitTransaction();
                this.FileManagerConnection.CommitTransaction();
                return(true);
            }
            catch (KnownException ex)
            {
                this.ConnectionHandler.RollBack();
                this.FileManagerConnection.RollBack();
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
            catch (Exception ex)
            {
                this.ConnectionHandler.RollBack();
                this.FileManagerConnection.RollBack();
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
        }
        public bool RemoveTeacher(IConnectionHandler handler, Guid workShopId, Guid teacherId)
        {
            var workShopTeacherBO = new WorkShopTeacherBO();
            var workShopTeacher   = workShopTeacherBO.Get(handler, workShopId, teacherId);

            if (workShopTeacher == null)
            {
                return(true);
            }
            if (!workShopTeacherBO.Delete(handler, workShopId, teacherId))
            {
                throw new Exception(Resources.Congress.ErrorInDeleteWorkShopTeacher);
            }
            return(true);
        }
        public bool AddTeacher(IConnectionHandler handler, Guid workShopId, Guid teacherId)
        {
            var workShopTeacherBO = new WorkShopTeacherBO();
            var shopTeacher       = workShopTeacherBO.Get(handler, workShopId, teacherId);

            if (shopTeacher != null)
            {
                return(true);
            }
            var workShopTeacher = new WorkShopTeacher {
                TeacherId = teacherId, WorkShopId = workShopId
            };

            if (!workShopTeacherBO.Insert(handler, workShopTeacher))
            {
                throw new Exception(Resources.Congress.ErrorInSaveWorkShopTeacher);
            }
            return(true);
        }
        public bool Update(WorkShop workShop, List <Guid> teacherList, HttpPostedFileBase fileProgram,
                           HttpPostedFileBase file)
        {
            try
            {
                this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted);
                this.FileManagerConnection.StartTransaction(IsolationLevel.ReadUncommitted);
                this.CommonConnection.StartTransaction(IsolationLevel.ReadUncommitted);
                var list = new WorkShopTeacherBO().Select(this.ConnectionHandler, x => x.TeacherId,
                                                          teacher => teacher.WorkShopId == workShop.Id);
                foreach (var guid in list)
                {
                    if (teacherList.All(guid1 => guid1 != guid))
                    {
                        if (!RemoveTeacher(this.ConnectionHandler, workShop.Id, guid))
                        {
                            throw new Exception(Resources.Congress.ErrorInDeleteWorkShopTeacher);
                        }
                    }
                }

                foreach (var guid in teacherList)
                {
                    if (list.All(guid1 => guid1 != guid))
                    {
                        if (!AddTeacher(this.ConnectionHandler, workShop.Id, guid))
                        {
                            throw new Exception(Resources.Congress.ErrorInSaveWorkShopTeacher);
                        }
                    }
                }
                var fileTransactionalFacade =
                    FileManagerComponent.Instance.FileTransactionalFacade(this.FileManagerConnection);
                if (fileProgram != null)
                {
                    if (workShop.ProgramAttachId.HasValue)
                    {
                        if (!fileTransactionalFacade.Update(fileProgram, (Guid)workShop.ProgramAttachId))
                        {
                            throw new Exception(Resources.Congress.ErrorInEditWorkShopProgramFile);
                        }
                    }
                    else
                    {
                        workShop.ProgramAttachId = fileTransactionalFacade.Insert(fileProgram);
                    }
                }
                if (file != null)
                {
                    if (workShop.FileAttachId.HasValue)
                    {
                        if (!fileTransactionalFacade.Update(file, (Guid)workShop.FileAttachId))
                        {
                            throw new Exception(Resources.Congress.ErrorInEditWorkShopAttachFile);
                        }
                    }
                    else
                    {
                        workShop.FileAttachId = fileTransactionalFacade.Insert(file);
                    }
                }

                if (!new WorkShopBO().Update(this.ConnectionHandler, workShop))
                {
                    throw new Exception(Resources.Congress.ErrorInEditWorkShop);
                }
                this.ConnectionHandler.CommitTransaction();
                this.CommonConnection.CommitTransaction();
                this.FileManagerConnection.CommitTransaction();
                return(true);
            }
            catch (KnownException ex)
            {
                this.ConnectionHandler.RollBack();
                this.FileManagerConnection.RollBack();
                this.CommonConnection.RollBack();
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
            catch (Exception ex)
            {
                this.ConnectionHandler.RollBack();
                this.FileManagerConnection.RollBack();
                this.CommonConnection.RollBack();
                Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace);
                throw new KnownException(ex.Message, ex);
            }
        }