Ejemplo n.º 1
0
        public ReleaseEventContract(ReleaseEvent ev, ContentLanguagePreference languagePreference, bool includeSeries = false, bool includeSeriesLinks = false)
            : this()
        {
            ParamIs.NotNull(() => ev);

            AdditionalNames = ev.Names.GetAdditionalNamesStringForLanguage(languagePreference);
            Category        = ev.Category;
            CustomName      = ev.CustomName;
            Date            = ev.Date;
            Deleted         = ev.Deleted;
            Description     = ev.Description;
            EndDate         = ev.EndDate;
            Id          = ev.Id;
            Name        = ev.TranslatedName[languagePreference];
            PictureMime = ev.PictureMime;
            SongList    = ObjectHelper.Convert(ev.SongList, s => new SongListBaseContract(s));
            Status      = ev.Status;
            UrlSlug     = ev.UrlSlug;
            Venue       = ObjectHelper.Convert(ev.Venue, v => new VenueContract(v, languagePreference, includeSeriesLinks));
            VenueName   = ev.VenueName;
            Version     = ev.Version;

            if (includeSeries && ev.HasSeries)
            {
                Series = new ReleaseEventSeriesContract(ev.Series, languagePreference, includeSeriesLinks);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取监控值
        /// </summary>
        private void GetMoniter()
        {
            string  vSql       = "select * from T_TEMPERATURE_MONITORING";
            DataSet vDsmoniter = App.GetDataSet(vSql);

            if (vDsmoniter.Tables.Count > 0 && vDsmoniter.Tables[0] != null && vDsmoniter.Tables[0].Rows != null && vDsmoniter.Tables[0].Rows.Count > 0)
            {
                m_Monitoring = ObjectHelper.Convert <TemperatureMonitoring>(vDsmoniter.Tables[0].Rows[0]);
            }
        }
 public CreatePermissionResponse Create(CreatePermissionRequest permission)
 {
     this.ValidateCreatePermissionRequest(permission);
     using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
     {
         IPermissionRepository perRepository = IoC.Container.Resolve <IPermissionRepository>(uow);
         Permission            per           = new Permission(permission.Name, permission.Key, permission.Description);
         perRepository.Add(per);
         uow.Commit();
         return(ObjectHelper.Convert <CreatePermissionResponse>(per));
     }
 }
 public CreateCategoryResponse Create(CreateCategoryRequest createCategoryRequest)
 {
     this.ValiateCreateCategoryRequest(createCategoryRequest);
     using (IUnitOfWork uow = new UnitOfWork(RepositoryType.MSSQL))
     {
         ICategoryRepository categoryRepository = IoC.Container.Resolve <ICategoryRepository>(uow);
         Category            category           = new Category(createCategoryRequest.Name, createCategoryRequest.Description);
         categoryRepository.Add(category);
         uow.Commit();
         return(ObjectHelper.Convert <CreateCategoryResponse>(category));
     }
 }
Ejemplo n.º 5
0
        public CreateUserResponse CreateUser(CreateUserRequest request)
        {
            this.ValidateCreateUserRequest(request);
            using (IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
            {
                User user = new User(request.Email, string.Empty, request.FirstName, request.LastName);

                IUserRepository userRepository = IoC.Container.Resolve <IUserRepository>(uow);
                userRepository.Add(user);
                uow.Commit();

                return(ObjectHelper.Convert <CreateUserResponse>(user));
            }
        }
Ejemplo n.º 6
0
 public CreateRoleResponse Create(CreateRoleRequest request)
 {
     this.Validate(request);
     using (App.Common.Data.IUnitOfWork uow = new App.Common.Data.UnitOfWork(RepositoryType.MSSQL))
     {
         IRoleRepository       roleRepository = IoC.Container.Resolve <IRoleRepository>(uow);
         IPermissionRepository permissionRepo = IoC.Container.Resolve <IPermissionRepository>(uow);
         IList <Permission>    permissions    = permissionRepo.GetPermissions(request.Permissions);
         Role role = new Role(request.Name, request.Description, permissions);
         roleRepository.Add(role);
         uow.Commit();
         return(ObjectHelper.Convert <CreateRoleResponse>(role));
     }
 }
        public GetUserGroupResponse Get(Guid id)
        {
            IUserGroupRepository  repository = IoC.Container.Resolve <IUserGroupRepository>();
            IPermissionRepository perRepo    = IoC.Container.Resolve <IPermissionRepository>();
            UserGroup             userGroup  = repository.GetById(id.ToString(), "Permissions");
            GetUserGroupResponse  response   = ObjectHelper.Convert <GetUserGroupResponse>(userGroup);

            response.PermissionIds = new List <Guid>();
            foreach (Permission per in userGroup.Permissions)
            {
                response.PermissionIds.Add(per.Id);
            }
            return(response);
        }
        //public HttpResponseMessage CreateThumbnail(Guid id, ThumbnailType type)
        //{
        //    ValidateCreateThumbnailRequest(id);
        //    IFileUploadRepository repo = IoC.Container.Resolve<IFileUploadRepository>();
        //    FileUpload file = repo.GetById(id.ToString());
        //    Stream fileStream = GetFileStream(file, type);
        //    StreamContent strContent = new StreamContent(fileStream);
        //    strContent.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(file.ContentType);

        //    HttpResponseMessage message = new HttpResponseMessage();
        //    message.Content = strContent;
        //    return message;
        //}

        //private Stream GetFileStream(FileUpload file, ThumbnailType type)
        //{
        //    Stream stream;
        //    Image img;
        //    switch (file.ContentType)
        //    {
        //        case FileContentType.Jpeg:
        //        case FileContentType.Png:
        //            byte[] contentInByte = Encoding.ASCII.GetBytes(file.Content);
        //            stream= new MemoryStream(contentInByte, 0, contentInByte.Length);
        //            //stream = new MemoryStream();
        //            //img = PhotoHelper.CreatePngStream(file.Content, type);
        //            //img.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
        //            break;

        //            //stream = new MemoryStream();
        //            //img = PhotoHelper.CreatePngStream(file.Content, type);
        //            //img.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
        //            //break;
        //        default:
        //            throw new ValidationException("common.httpError.unsupportedContent");
        //    }
        //    return stream;
        //}

        //private void ValidateCreateThumbnailRequest(Guid id)
        //{
        //    IFileUploadRepository repo = IoC.Container.Resolve<IFileUploadRepository>();
        //    FileUpload file = repo.GetById(id.ToString());
        //    if (file == null)
        //    {
        //        throw new ValidationException("common.httpError.notFound");
        //    }
        //}

        //public IList<TEntity> GetByParentId<TEntity>(Guid parentId) where TEntity : IMappedFrom<FileUpload>
        //{
        //    IFileUploadRepository repo = IoC.Container.Resolve<IFileUploadRepository>();
        //    return repo.GetByParentId<TEntity>(parentId);
        //}

        //public FilesUploadResponse UploadFiles(Guid parentId, HttpFileCollection files)
        //{
        //    FilesUploadResponse uploadResponse = new FilesUploadResponse();
        //    ValidateUploadFilesRequest(parentId);
        //    using (IUnitOfWork uow = new UnitOfWork(new AppDbContext(IOMode.Write)))
        //    {
        //        IFileUploadRepository fileRepo = IoC.Container.Resolve<IFileUploadRepository>(uow);
        //        foreach (string fileKey in files)
        //        {
        //            HttpPostedFile file = files[fileKey];
        //            FileUpload fileUpload = new FileUpload(file);
        //            fileUpload.ParentId = parentId;
        //            fileRepo.Add(fileUpload);
        //            uploadResponse.File = fileUpload.Id;
        //        }
        //        uow.Commit();
        //    }
        //    return uploadResponse;
        //}

        //private void ValidateUploadFilesRequest(Guid parentId)
        //{
        //    if (parentId == null)
        //    {
        //        throw new ValidationException("common.fileUpload.invalidParentId");
        //    }
        //}

        //public FileUpload GetById(Guid id)
        //{
        //    IFileUploadRepository repo = IoC.Container.Resolve<IFileUploadRepository>();
        //    return repo.GetById(id.ToString());
        //}

        //public FilesUploadResponse UploadFiles(Guid parentId, IList<FileUploadInfo> files)
        //{
        //    FilesUploadResponse uploadResponse = new FilesUploadResponse();
        //    ValidateUploadFilesRequest(parentId);
        //    using (IUnitOfWork uow = new UnitOfWork(new AppDbContext(IOMode.Write)))
        //    {
        //        IFileUploadRepository fileRepo = IoC.Container.Resolve<IFileUploadRepository>(uow);
        //        foreach (FileUploadInfo file in files)
        //        {
        //            FileUpload fileUpload = new FileUpload(file);
        //            fileUpload.ParentId = parentId;
        //            fileRepo.Add(fileUpload);
        //            uploadResponse.File = fileUpload.Id;
        //        }
        //        uow.Commit();
        //    }
        //    return uploadResponse;
        //}
        public IList <FileUploadResponse> UploadFiles(List <MultipartFormDataMemoryStreamProvider.FileInfo> files)
        {
            ValidateUploadRequest(files);
            using (IUnitOfWork uow = new UnitOfWork(new AppDbContext(IOMode.Write)))
            {
                IFileRepository            repo          = IoC.Container.Resolve <IFileRepository>(uow);
                IList <FileUploadResponse> filesUploaded = new List <FileUploadResponse>();
                foreach (App.Common.Providers.MultipartFormDataMemoryStreamProvider.FileInfo file in files)
                {
                    App.Entity.Common.FileUpload fileCreated = new Entity.Common.FileUpload(file.FileName, file.ContentType, file.FileSize, file.Content);
                    repo.Add(fileCreated);
                    filesUploaded.Add(ObjectHelper.Convert <FileUploadResponse>(fileCreated));
                }
                uow.Commit();
                return(filesUploaded);
            }
        }
Ejemplo n.º 9
0
        public ReleaseEventContract(ReleaseEvent ev, bool includeSeries = false)
            : this()
        {
            ParamIs.NotNull(() => ev);

            CustomName  = ev.CustomName;
            Date        = ev.Date;
            Description = ev.Description;
            Id          = ev.Id;
            Name        = ev.Name;
            PictureMime = ev.PictureMime;
            SongList    = ObjectHelper.Convert(ev.SongList, s => new SongListBaseContract(s));
            UrlSlug     = ev.UrlSlug;
            Venue       = ev.Venue;
            Version     = ev.Version;

            if (includeSeries && ev.Series != null)
            {
                Series = new ReleaseEventSeriesContract(ev.Series);
            }
        }
        public void Handle(UserNameAndPwdAuthenticationRequest command)
        {
            this.ValidateUserNameAndPwdAuthenticationRequest(command);
            using (IUnitOfWork uow = this.CreateUnitOfWork <User>())
            {
                IUserRepository repository = IoC.Container.Resolve <IUserRepository>(uow);
                User            user       = repository.GetActiveUser(command.UserName, EncodeHelper.EncodePassword(command.Password));
                if (user == null)
                {
                    command.Result = new AuthenticationResult(false);
                    this.Publish(new OnAuthenticationFailed(command.UserName, command.Password, DateTime.UtcNow));
                    return;
                }
                user.GenerateLoginToken();
                repository.Update(user);
                uow.Commit();

                command.Result         = ObjectHelper.Convert <AuthenticationResult>(user);
                command.Result.IsValid = true;

                this.Publish(new OnAuthenticationSuccess(user.FirstName, user.LastName, user.Email, user.LoginToken, user.TokenExpiredAfter, DateTime.UtcNow));
            }
        }
 /// <summary>
 /// Need to have mapp config for source and TEntity
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="source"></param>
 /// <returns></returns>
 public static TEntity To <TEntity>(this object source)
 {
     return(ObjectHelper.Convert <TEntity>(source));
 }