private void GetImportListProxy(SpecLabEntities _entities,
                                        DatabaseCommand <GetImportListParams, List <ImportNoteShortData> > paramCommand)
        {
            var importQuery = (from import in _entities.Imports
                               select import);

            if (!string.IsNullOrEmpty(paramCommand.CallingInfo.ImportId))
            {
                importQuery = importQuery.Where(e => e.ImportId.StartsWith(paramCommand.CallingInfo.ImportId));
            }

            if (paramCommand.CallingInfo.StartDate != null)
            {
                importQuery = importQuery.Where(e => e.ImportDate >= paramCommand.CallingInfo.StartDate);
            }

            if (paramCommand.CallingInfo.EndDate != null)
            {
                var limitDate = paramCommand.CallingInfo.EndDate.GetValueOrDefault().AddDays(1);
                importQuery = importQuery.Where(e => e.ImportDate < limitDate);
            }

            var listResult = importQuery.Select(t => new ImportNoteShortData()
            {
                ImportId     = t.ImportId,
                ImportUserId = t.ImportUserId,
                ImportDate   = t.ImportDate,
                NumberImport = t.SampleNumber
            });

            listResult = listResult.OrderByDescending(t => t.ImportDate);

            paramCommand.ReturnValue.AddRange(listResult);
        }
Beispiel #2
0
        private void DeleteStorageInfoProxy(SpecLabEntities _entities,
                                            DatabaseCommand <string, object> paramCommand)
        {
            var existStorage = (from storage in _entities.Storages
                                where storage.StorageId.Equals(paramCommand.CallingInfo, StringComparison.OrdinalIgnoreCase)
                                select storage).FirstOrDefault();

            if (existStorage == null)
            {
                throw new BusinessException(ErrorCode.StorageIdNotExists, paramCommand.CallingInfo);
            }
            else
            {
                var checkStorageInUse = (from exists in _entities.TubeSamples
                                         where exists.StorageId == paramCommand.CallingInfo
                                         select exists.StorageId);
                if (checkStorageInUse.Any())
                {
                    throw new BusinessException(ErrorCode.StorageIdAlreadyInUse);
                }

                checkStorageInUse = (from exists in _entities.SampleHistories
                                     where exists.StorageId == paramCommand.CallingInfo
                                     select exists.StorageId);
                if (checkStorageInUse.Any())
                {
                    throw new BusinessException(ErrorCode.StorageIdAlreadyInUse);
                }

                _entities.Storages.Remove(existStorage);
                _entities.SaveChanges();
            }
        }
        private void GetRemovalListProxy(SpecLabEntities _entities,
                                         DatabaseCommand <GetRemovalListParams, List <RemovalNoteShortData> > paramCommand)
        {
            var removalQuery = (from import in _entities.Removals
                                select import);

            if (!string.IsNullOrEmpty(paramCommand.CallingInfo.RemovalId))
            {
                removalQuery = removalQuery.Where(e => e.RemovalId.StartsWith(paramCommand.CallingInfo.RemovalId));
            }

            if (paramCommand.CallingInfo.StartDate != null)
            {
                removalQuery = removalQuery.Where(e => e.RemovalDate >= paramCommand.CallingInfo.StartDate);
            }

            if (paramCommand.CallingInfo.EndDate != null)
            {
                var limitDate = paramCommand.CallingInfo.EndDate.GetValueOrDefault().AddDays(1);
                removalQuery = removalQuery.Where(e => e.RemovalDate < limitDate);
            }

            removalQuery = removalQuery.OrderByDescending(t => t.RemovalDate);

            var listResult = removalQuery.Select(t => new RemovalNoteShortData()
            {
                RemovalId     = t.RemovalId,
                RemovalUserId = t.RemovalUserId,
                RemovalDate   = t.RemovalDate,
                RemovalReason = t.RemovalReason,
                NumberRemoval = t.SampleNumber
            });

            paramCommand.ReturnValue.AddRange(listResult);
        }
        private void GetLoginUserInfoProxy(SpecLabEntities _entities,
                                           DatabaseCommand <string, LoginUserInfo> paramCommand)
        {
            if (paramCommand.CallingInfo != null)
            {
                if (CommonConstant.SystemAdmin.ToLower().Equals(paramCommand.CallingInfo.ToLower()))
                {
                    paramCommand.ReturnValue = GetSystemAdminLoginInfo();
                }
                else
                {
                    var dbItem = _entities.UserInfoes
                                 .FirstOrDefault(u => u.UserId.ToLower().Equals(paramCommand.CallingInfo.ToLower()));

                    if (dbItem != null)
                    {
                        var existsUser = new LoginUserInfo()
                        {
                            FullName = dbItem.FullName,
                            UserId   = dbItem.UserId,
                            Status   = CommonUtils.GetEnumFromValue <UserStatus>(dbItem.Status)
                        };

                        var rights = dbItem.UserRights.ToList();

                        existsUser.Rights.AddRange(dbItem.UserRights.ToList().ConvertAll(ConvertUserRightCode));

                        paramCommand.ReturnValue = existsUser;
                    }
                }
            }
        }
        private void UpdateUserRightsProxy(SpecLabEntities _entities,
                                           DatabaseCommand <UpdateRightParams, bool> paramCommand)
        {
            var listRights = (from u in _entities.UserRights
                              where u.UserInfo.UserId.ToLower().Equals(paramCommand.CallingInfo.UserId.ToLower())
                              select u);

            foreach (var right in listRights)
            {
                _entities.UserRights.Remove(right);
            }
            _entities.SaveChanges();

            foreach (var rightCode in paramCommand.CallingInfo.UpdateRights)
            {
                _entities.UserRights.Add(new UserRight()
                {
                    CreateDate = DateTime.Now,
                    UpdateDate = DateTime.Now,
                    UserId     = paramCommand.CallingInfo.UserId,
                    RightCode  = rightCode.ToString()
                });
            }
            _entities.SaveChanges();

            paramCommand.ReturnValue = true;
        }
Beispiel #6
0
        private void AddStorageInfoProxy(SpecLabEntities _entities,
                                         DatabaseCommand <ShortStorageInfo, object> paramCommand)
        {
            var existStorage = (from storage in _entities.Storages
                                where storage.StorageId.Equals(paramCommand.CallingInfo.StorageId, StringComparison.OrdinalIgnoreCase)
                                select storage).FirstOrDefault();

            if (existStorage != null)
            {
                throw new BusinessException(ErrorCode.StorageIdExists);
            }
            else
            {
                _entities.Storages.Add(new Storage()
                {
                    UpdateDate    = DateTime.Now,
                    CreateDate    = DateTime.Now,
                    NumberStorage = paramCommand.CallingInfo.NumberStorage,
                    NumColumn     = paramCommand.CallingInfo.NumColumn,
                    NumRows       = paramCommand.CallingInfo.NumRows,
                    StorageId     = paramCommand.CallingInfo.StorageId
                });

                _entities.SaveChanges();
            }
        }
        private void GetExportHistoryProxy(SpecLabEntities _entities,
                                           DatabaseCommand <GetExportHistoryParam, List <ReportExportHistoryInfo> > paramCommand)
        {
            var historyQuery = (from history in _entities.viewExportHistories
                                select history);

            if (paramCommand.CallingInfo.StartDate != null)
            {
                historyQuery = historyQuery.Where(history => history.ExportDate >= paramCommand.CallingInfo.StartDate);
            }

            if (paramCommand.CallingInfo.EndDate != null)
            {
                var limitDate = paramCommand.CallingInfo.EndDate.GetValueOrDefault().AddDays(1);
                historyQuery = historyQuery.Where(history => history.ExportDate < limitDate);
            }

            historyQuery = historyQuery.OrderByDescending(history => history.ExportDate);

            var listResult = historyQuery.Select(history => new ReportExportHistoryInfo()
            {
                TubeId         = history.TubeId,
                ExportDate     = history.ExportDate,
                ExportUserId   = history.ExportUserId,
                ExportReason   = history.ExportReason,
                SampleType     = (SampleType)history.SampleType,
                UpdateDate     = history.UpdateDate,
                UpdateUserId   = history.UpdateUserId,
                StorageId      = history.StorageId,
                MaximumStorage = history.NumberStorage,
                LocationNum    = history.LocationNum
            });

            paramCommand.ReturnValue.AddRange(listResult);
        }
        private void SaveContentProxy(SpecLabEntities _entities,
                                      DatabaseCommand <ContentInfo, object> paramCommand)
        {
            var existContent = (from content in _entities.Contents
                                where content.ContentId == paramCommand.CallingInfo.ContentId
                                select content).FirstOrDefault();

            var loginInfo = SessionUtils.LoginUserInfo;

            if (existContent == null)
            {
                //throw new BusinessException(ErrorCode.ContentIdNotExists, paramCommand.CallingInfo);
                _entities.Contents.Add(new Content()
                {
                    CreateUser  = loginInfo == null ? null : loginInfo.UserId,
                    UpdateUser  = loginInfo == null ? null : loginInfo.UserId,
                    UpdateDate  = DateTime.Now,
                    CreateDate  = DateTime.Now,
                    ContentId   = paramCommand.CallingInfo.ContentId,
                    ContentText = paramCommand.CallingInfo.ContentText
                });
                _entities.SaveChanges();
            }
            else
            {
                existContent.UpdateDate  = DateTime.Now;
                existContent.UpdateUser  = loginInfo == null ? null : loginInfo.UserId;
                existContent.ContentText = paramCommand.CallingInfo.ContentText;
                _entities.SaveChanges();
            }
        }
        private void ChangePasswordProxy(SpecLabEntities _entities,
                                         DatabaseCommand <ChangePassParams, bool> paramCommand)
        {
            paramCommand.ReturnValue = false;

            var selectedUser = (from u in _entities.UserInfoes
                                where u.UserId.ToLower().Equals(paramCommand.CallingInfo.UserId.ToLower())
                                select u).FirstOrDefault();

            if (selectedUser == null)
            {
                throw new BusinessException(ErrorCode.UserIdNotExists);
            }
            else
            {
                string passwordHash = GeneratePasswordHash(
                    paramCommand.CallingInfo.OldPass, selectedUser.PasswordSalt);
                if (!passwordHash.Equals(selectedUser.Password))
                {
                    throw new BusinessException(ErrorCode.PasswordNotMatch);
                }
                else
                {
                    string passwordSalt = Guid.NewGuid().ToString();
                    passwordHash = GeneratePasswordHash(paramCommand.CallingInfo.NewPass, passwordSalt);

                    selectedUser.Password     = passwordHash;
                    selectedUser.PasswordSalt = passwordSalt;

                    _entities.SaveChanges();

                    paramCommand.ReturnValue = true;
                }
            }
        }
        private void GetSampleStatisticsProxy(SpecLabEntities _entities,
                                              DatabaseCommand <string, List <ReportSampleStatisticInfo> > paramCommand)
        {
            var query = _entities.viewSampleStatistics
                        .Where(statistic => statistic.Status != (int)TubeSampleStatus.Remove);

            paramCommand.ReturnValue = query.ToList().ConvertAll(ConvertReportSampleStatisticInfo);
        }
        private void GetAllShortUserInfoProxy(SpecLabEntities _entities,
                                              DatabaseCommand <object, List <ShortUserInfo> > paramCommand)
        {
            var userStatusEnable = UserStatus.Enable.ToString();
            var listUsers        = (from u in _entities.UserInfoes
                                    where u.Status.Equals(userStatusEnable)
                                    select u).ToList();

            paramCommand.ReturnValue = listUsers.ConvertAll(ConvertToShortUserInfo);
        }
        private void UpdateUserProxy(SpecLabEntities _entities,
                                     DatabaseCommand <LoginUserInfo, LoginUserInfo> paramCommand)
        {
            var dbItem = _entities.UserInfoes
                         .FirstOrDefault(c => c.UserId.ToLower().Equals(
                                             paramCommand.CallingInfo.UserId));

            dbItem.FullName = paramCommand.CallingInfo.FullName;
            _entities.SaveChanges();

            paramCommand.ReturnValue = this.GetLoginUserInfo(paramCommand.CallingInfo.UserId);
        }
Beispiel #13
0
        private void GetListStorageIdProxy(SpecLabEntities _entities,
                                           DatabaseCommand <object, List <ShortStorageInfo> > paramCommand)
        {
            var listStorageId = (from u in _entities.Storages
                                 select new ShortStorageInfo()
            {
                StorageId = u.StorageId,
                NumberStorage = u.NumberStorage,
                NumRows = u.NumRows,
                NumColumn = u.NumColumn
            }).ToList();

            paramCommand.ReturnValue = listStorageId;
        }
        private void CreateNewUserProxy(SpecLabEntities _entities,
                                        DatabaseCommand <CreateNewUserParams, LoginUserInfo> paramCommand)
        {
            if (paramCommand.CallingInfo.LoginUserInfo.UserId.Equals(CommonConstant.SystemAdmin))
            {
                throw new BusinessException(ErrorCode.UserIdExists);
            }

            var existsUser = _entities.UserInfoes
                             .FirstOrDefault(u => u.UserId.ToLower()
                                             .Equals(paramCommand.CallingInfo.LoginUserInfo.UserId.ToLower()));

            if (existsUser != null)
            {
                throw new BusinessException(ErrorCode.UserIdExists);
            }
            else
            {
                string passwordSalt = Guid.NewGuid().ToString();
                string paswordHash  = GeneratePasswordHash(paramCommand.CallingInfo.Password, passwordSalt);

                var dbItem = new UserInfo()
                {
                    UserId       = paramCommand.CallingInfo.LoginUserInfo.UserId,
                    FullName     = paramCommand.CallingInfo.LoginUserInfo.FullName,
                    CreateDate   = DateTime.Now,
                    UpdateDate   = DateTime.Now,
                    Password     = paswordHash,
                    PasswordSalt = passwordSalt,
                    Status       = UserStatus.Enable.ToString()
                };
                _entities.UserInfoes.Add(dbItem);

                foreach (var rightCode in paramCommand.CallingInfo.LoginUserInfo.Rights)
                {
                    _entities.UserRights.Add(new UserRight()
                    {
                        CreateDate = DateTime.Now,
                        UpdateDate = DateTime.Now,
                        UserId     = paramCommand.CallingInfo.LoginUserInfo.UserId,
                        RightCode  = rightCode.ToString()
                    });
                }

                _entities.SaveChanges();

                paramCommand.ReturnValue = this.GetLoginUserInfo(paramCommand.CallingInfo.LoginUserInfo.UserId);
            }
        }
 public static Header GetHeader(string _labId)
 {
     using (SpecLabEntities _entities = CommonUtils.GetBusinessObject <SpecLabEntities>())
     {
         try
         {
             var query = _entities.Headers.Where(o => o.LabID == _labId).FirstOrDefault();
             return(query);
         }
         catch (Exception ex)
         {
             _logger.Error(string.Format("Failed to saved database: {0}", ex));
             return(null);
         }
     }
 }
        private void GetTubeExportCountProxy(SpecLabEntities _entities,
                                             DatabaseCommand <GetTubeExportCountParams, List <TubeExportCount> > paramCommand)
        {
            var query = (from tube in _entities.TubeSamples
                         select new TubeExportCount()
            {
                TubeId = tube.TubeId,
                NumberExport = tube.NumberExport
            });

            if (paramCommand.CallingInfo.TubeIds.Count > 0)
            {
                query = query.Where(t => paramCommand.CallingInfo.TubeIds.Contains(t.TubeId));
            }

            paramCommand.ReturnValue = query.ToList();
        }
        private void DeleteUserProxy(SpecLabEntities _entities,
                                     DatabaseCommand <string, bool> paramCommand)
        {
            var userInfo = (from u in _entities.UserInfoes
                            where u.UserId.Equals(paramCommand.CallingInfo)
                            select u).FirstOrDefault();

            var listRightDelete = userInfo.UserRights.ToList();

            foreach (var rightDelete in listRightDelete)
            {
                _entities.UserRights.Remove(rightDelete);
            }
            _entities.UserInfoes.Remove(userInfo);
            _entities.SaveChanges();

            paramCommand.ReturnValue = true;
        }
        private void GetSampleSpecProxy(SpecLabEntities _entities,
                                        DatabaseCommand <string, SampleSpecInfo> paramCommand)
        {
            var sampleDbItem = (from sample in _entities.SampleSpecs
                                where sample.SampleSpecId.Equals(
                                    paramCommand.CallingInfo, StringComparison.OrdinalIgnoreCase)
                                select sample).FirstOrDefault();

            if (sampleDbItem == null)
            {
                throw new BusinessException(ErrorCode.SampleSpecIdNotExists);
            }

            SampleSpecInfo info = new SampleSpecInfo()
            {
                LocationId   = sampleDbItem.Source,
                PatientName  = sampleDbItem.PatientName,
                SampleSpecId = sampleDbItem.SampleSpecId,
                YearOfBirth  = sampleDbItem.Age,
                Sex          = (SampleSex)sampleDbItem.Sex[0],
                UserInput    = sampleDbItem.UserInput,
                DateInput    = sampleDbItem.DateInput
            };

            var tubeListDbItem = (from tube in _entities.TubeSamples
                                  where tube.SampleSpecId.Equals(
                                      paramCommand.CallingInfo, StringComparison.OrdinalIgnoreCase)
                                  select new TubeSampleSpecInfo()
            {
                Volume = tube.Volume,
                LocationNum = tube.LocationNum,
                SampleSpecId = tube.SampleSpecId,
                StorageId = tube.StorageId,
                TubeId = tube.TubeId,
                Status = (TubeSampleStatus)tube.Status,
                DateInput = sampleDbItem.DateInput,
                Type = (TubeSampleType)tube.TubeType,
                SampleType = (SampleType)tube.SampleType,
            }).ToList();

            info.TubeSampleSpecs.AddRange(tubeListDbItem);

            paramCommand.ReturnValue = info;
        }
        /// <summary>
        /// kiểm tra storage id
        /// </summary>
        /// <param name="_entities"></param>
        /// <param name="storageId"></param>
        private void ValidateStorageId(SpecLabEntities _entities, string storageId, int locationNum)
        {
            var query = (from storage in _entities.Storages
                         where storage.StorageId.Equals(storageId, StringComparison.OrdinalIgnoreCase)
                         select storage.NumberStorage);

            if (!query.Any())
            {
                throw new BusinessException(ErrorCode.StorageIdNotExists, storageId);
            }
            else
            {
                var numberStorage = query.FirstOrDefault();
                if (locationNum > numberStorage)
                {
                    throw new BusinessException(ErrorCode.StorageLocationOutOfBound, storageId, numberStorage);
                }
            }
        }
Beispiel #20
0
        private void UpdateStorageInfoProxy(SpecLabEntities _entities,
                                            DatabaseCommand <ShortStorageInfo, object> paramCommand)
        {
            var existStorage = (from storage in _entities.Storages
                                where storage.StorageId.Equals(paramCommand.CallingInfo.StorageId, StringComparison.OrdinalIgnoreCase)
                                select storage).FirstOrDefault();

            if (existStorage == null)
            {
                throw new BusinessException(ErrorCode.StorageIdNotExists, paramCommand.CallingInfo.StorageId);
            }
            else
            {
                existStorage.NumberStorage = paramCommand.CallingInfo.NumberStorage;
                existStorage.NumRows       = paramCommand.CallingInfo.NumRows;
                existStorage.NumColumn     = paramCommand.CallingInfo.NumColumn;
                _entities.SaveChanges();
            }
        }
        private void GetRemovalInfoProxy(SpecLabEntities _entities,
                                         DatabaseCommand <string, RemovalNote> paramCommand)
        {
            var result = (from removal in _entities.Removals
                          where removal.RemovalId.Equals(
                              paramCommand.CallingInfo, StringComparison.OrdinalIgnoreCase)
                          select new RemovalNote()
            {
                RemovalDate = removal.RemovalDate,
                RemovalId = removal.RemovalId,
                RemovalUserId = removal.RemovalUserId,
                RemovalReason = removal.RemovalReason,
            }).FirstOrDefault();

            if (result == null)
            {
                throw new BusinessException(ErrorCode.RemovalIdNotExists);
            }

            var listRemovalDetail = (from removalDetail in _entities.RemovalDetails
                                     join tube in _entities.TubeSamples on removalDetail.TubeId equals tube.TubeId
                                     join spec in _entities.SampleSpecs on tube.SampleSpecId equals spec.SampleSpecId
                                     where removalDetail.RemovalId.Equals(
                                         paramCommand.CallingInfo, StringComparison.OrdinalIgnoreCase)
                                     select new RemovalNoteDetail()
            {
                RemovalId = removalDetail.RemovalId,
                TubeId = removalDetail.TubeId,
                RemovalDetailId = removalDetail.RemovalDetailId,
                Status = (TubeSampleStatus)removalDetail.Status,
                Type = (TubeSampleType)removalDetail.TubeType,
                Volume = removalDetail.Volume,
                LocationNum = removalDetail.LocationNum,
                StorageId = removalDetail.StorageId,
                SampleSpecId = tube.SampleSpecId,
                InputDate = spec.DateInput,
                NumberExport = removalDetail.NumberExport
            }).ToList();

            result.RemovalNoteDetails.AddRange(listRemovalDetail);

            paramCommand.ReturnValue = result;
        }
        private void GetImportInfoProxy(SpecLabEntities _entities,
                                        DatabaseCommand <string, ImportNote> paramCommand)
        {
            var result = (from import in _entities.Imports
                          where import.ImportId.Equals(
                              paramCommand.CallingInfo, StringComparison.OrdinalIgnoreCase)
                          select new ImportNote()
            {
                ImportDate = import.ImportDate,
                ImportId = import.ImportId,
                ImportUserId = import.ImportUserId,
            }).FirstOrDefault();

            if (result == null)
            {
                throw new BusinessException(ErrorCode.ExportIdNotExists);
            }

            var listExportDetail = (from importDetail in _entities.ImportDetails
                                    join import in _entities.Imports on importDetail.ImportId equals import.ImportId
                                    join tube in _entities.TubeSamples on importDetail.TubeId equals tube.TubeId
                                    where importDetail.ImportId.Equals(
                                        paramCommand.CallingInfo, StringComparison.OrdinalIgnoreCase)
                                    select new ImportNoteDetail()
            {
                ImportId = importDetail.ImportId,
                TubeId = importDetail.TubeId,
                ImportDetailId = importDetail.ImportDetailId,
                Status = (TubeSampleStatus)importDetail.Status,
                Type = (TubeSampleType)importDetail.TubeType,
                Volume = importDetail.Volume,
                LocationNum = importDetail.LocationNum,
                StorageId = importDetail.StorageId,
                SampleSpecId = tube.SampleSpecId,
                SampleType = (SampleType)tube.SampleType,
                ImportDate = import.ImportDate,
                NumberExport = importDetail.NumberExport
            }).ToList();

            result.ImportNoteDetails.AddRange(listExportDetail);

            paramCommand.ReturnValue = result;
        }
        private void GetNumberRemovalProxy(SpecLabEntities _entities,
                                           DatabaseCommand <GetNumberRemovalParams, int> paramCommand)
        {
            var query = (from Removal in _entities.Removals
                         select Removal);

            if (paramCommand.CallingInfo.FromDate != null)
            {
                query = query.Where(t => t.RemovalDate >= paramCommand.CallingInfo.FromDate);
            }

            if (paramCommand.CallingInfo.ToDate != null)
            {
                var limitDate = paramCommand.CallingInfo.ToDate.GetValueOrDefault().AddDays(1);
                query = query.Where(t => t.RemovalDate < limitDate);
            }

            paramCommand.ReturnValue = query.Count();
        }
        private void GetLoginUserInfoProxy(SpecLabEntities _entities,
                                           DatabaseCommand <LoginParams, LoginUserInfo> paramCommand)
        {
            if (paramCommand.CallingInfo.Username.ToLower().Equals(CommonConstant.SystemAdmin.ToLower()))
            {
                string password = GeneratePasswordSystemAdmin();
                if (paramCommand.CallingInfo.Password.Equals(password))
                {
                    paramCommand.ReturnValue = this.GetSystemAdminLoginInfo();
                }
                else
                {
                    throw new BusinessException(ErrorCode.PasswordNotMatch);
                }
            }
            else
            {
                var existsUser = _entities.UserInfoes.FirstOrDefault(u => u.UserId.ToLower()
                                                                     .Equals(paramCommand.CallingInfo.Username.ToLower()));

                if (existsUser == null)
                {
                    throw new BusinessException(ErrorCode.UserIdNotExists);
                }
                else if (!existsUser.Status.ToString().Equals(UserStatus.Enable.ToString()))
                {
                    throw new BusinessException(ErrorCode.UserNotActive);
                }
                else
                {
                    string passwordHash = GeneratePasswordHash(
                        paramCommand.CallingInfo.Password,
                        existsUser.PasswordSalt);
                    if (!passwordHash.Equals(existsUser.Password))
                    {
                        throw new BusinessException(ErrorCode.PasswordNotMatch);
                    }

                    paramCommand.ReturnValue = this.GetLoginUserInfo(paramCommand.CallingInfo.Username);
                }
            }
        }
        private void GetContentInfoByIdProxy(SpecLabEntities _entities,
                                             DatabaseCommand <string, ContentInfo> paramCommand)
        {
            var existContent = (from u in _entities.Contents
                                where u.ContentId == paramCommand.CallingInfo
                                select new ContentInfo()
            {
                ContentId = u.ContentId,
                ContentText = u.ContentText
            }).FirstOrDefault();

            if (existContent == null)
            {
                throw new BusinessException(ErrorCode.ContentIdNotExists, paramCommand.CallingInfo);
            }
            else
            {
                paramCommand.ReturnValue = existContent;
            }
        }
        private void GetTubeDetailProxy(SpecLabEntities _entities,
                                        DatabaseCommand <string, TubeSampleSpecInfo> paramCommand)
        {
            var summaryInfo = (from tube in _entities.TubeSamples
                               join sample in _entities.SampleSpecs on tube.SampleSpecId equals sample.SampleSpecId
                               where tube.TubeId == paramCommand.CallingInfo
                               select new TubeSampleSpecInfo()
            {
                DateInput = sample.DateInput,
                LocationNum = tube.LocationNum,
                StorageId = tube.StorageId,
                Status = (TubeSampleStatus)tube.Status,
                Type = (TubeSampleType)tube.TubeType,
                TubeId = tube.TubeId,
                Volume = tube.Volume,
                SampleSpecId = tube.SampleSpecId
            }).FirstOrDefault();

            paramCommand.ReturnValue = summaryInfo;
        }
        private void GetStorageStatisticsProxy(SpecLabEntities _entities,
                                               DatabaseCommand <string, List <ReportStorageStatisticsInfo> > paramCommand)
        {
            var query = _entities.viewStorageStatistics
                        .Where(statistic => statistic.Status != (int)TubeSampleStatus.Remove)
                        .OrderBy(statistic => statistic.StorageId)
                        .ThenBy(statistic => statistic.LocationNum)
                        .Select(statistic => new ReportStorageStatisticsInfo()
            {
                StorageId      = statistic.StorageId,
                LocationNum    = statistic.LocationNum,
                TubeId         = statistic.TubeId,
                Status         = (TubeSampleStatus)statistic.Status,
                MaximumStorage = statistic.NumberStorage,
                Volume         = statistic.Volume,
                NumberExport   = statistic.NumberExport
            });

            paramCommand.ReturnValue = query.ToList();
        }
 protected DatabaseCommand <InVal, ReturnVal> ProxyCalling <InVal, ReturnVal>(
     Action <SpecLabEntities, DatabaseCommand <InVal, ReturnVal> > actionEntity,
     DatabaseCommand <InVal, ReturnVal> dbCommandInfo)
 {
     using (SpecLabEntities _entities = CommonUtils.GetBusinessObject <SpecLabEntities>())
     {
         try
         {
             actionEntity(_entities, dbCommandInfo);
             return(dbCommandInfo);
         }
         catch (DbUpdateException updateException)
         {
             _logger.Error(string.Format("Failed to saved database: {0}", updateException));
             throw new BusinessException(ErrorCode.InternalErrorException, updateException);
         }
         catch (DbEntityValidationException entityValidationException)
         {
             _logger.Error(string.Format("Failed to saved database: {0}", entityValidationException));
             foreach (var entityValidationError in entityValidationException.EntityValidationErrors)
             {
                 foreach (var error in entityValidationError.ValidationErrors)
                 {
                     _logger.ErrorFormat("Failed to saved database: {0}", error.ErrorMessage);
                 }
             }
             throw new BusinessException(ErrorCode.InternalErrorException, entityValidationException);
         }
         catch (BusinessException)
         {
             throw;
         }
         catch (Exception exception)
         {
             _logger.Error(string.Format("Iternal error: {0}", exception));
             throw new BusinessException(ErrorCode.InternalErrorException, exception);
         }
     }
 }
        private void GetImportHistoryProxy(SpecLabEntities _entities,
                                           DatabaseCommand <string, List <SampleHistoryInfo> > paramCommand)
        {
            var sampleDbItem = (from sample in _entities.SampleSpecs
                                where sample.SampleSpecId.Equals(
                                    paramCommand.CallingInfo, StringComparison.OrdinalIgnoreCase)
                                select sample).FirstOrDefault();

            if (sampleDbItem == null)
            {
                throw new BusinessException(ErrorCode.SampleSpecIdNotExists);
            }

            var historyListDbItem = (from tube in _entities.TubeSamples
                                     join history in _entities.SampleHistories on tube.TubeId equals history.TubeId
                                     where tube.SampleSpecId.Equals(paramCommand.CallingInfo, StringComparison.OrdinalIgnoreCase) &&
                                     history.Action == (int)HistoryAction.Import
                                     select new SampleHistoryInfo()
            {
                HistoryId = history.HistoryId,
                TubeId = history.TubeId,
                HistoryDate = history.HistoryDate,
                Action = (HistoryAction)history.Action,
                UserId = history.UserId,
                Description = history.Description,
                LocationNum = history.LocationNum,
                StorageId = history.StorageId,
                Status = (TubeSampleStatus)history.Status,
                Type = (TubeSampleType)history.TubeType,
                Volume = history.Volume
            });

            List <SampleHistoryInfo> listData = new List <SampleHistoryInfo>();

            listData.AddRange(historyListDbItem);

            paramCommand.ReturnValue = listData;
        }
        private void GetTubeHistoryProxy(SpecLabEntities _entities,
                                         DatabaseCommand <string, List <SampleHistoryInfo> > paramCommand)
        {
            var historyQuery = (from history in _entities.SampleHistories
                                where history.TubeId == paramCommand.CallingInfo
                                select new SampleHistoryInfo()
            {
                HistoryId = history.HistoryId,
                TubeId = history.TubeId,
                HistoryDate = history.HistoryDate,
                Action = (HistoryAction)history.Action,
                UserId = history.UserId,
                Description = history.Description,
                LocationNum = history.LocationNum,
                StorageId = history.StorageId,
                Status = (TubeSampleStatus)history.Status,
                Type = (TubeSampleType)history.TubeType,
                Volume = history.Volume,
                NumberExport = history.NumberExport,
            });

            historyQuery = historyQuery.OrderByDescending(his => his.HistoryDate);
            paramCommand.ReturnValue.AddRange(historyQuery);
        }