예제 #1
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var photographer = await _context.FindAsync <Photographer>(request.PhotographerId);

                var company = request.Company.CompanyId != default
                    ? await _context.FindAsync <Company>(request.Company.CompanyId)
                    : new Company();

                photographer.AddCompany(company.CompanyId);

                _context.Add(photographer);

                _context.Add(company);

                await _context.SaveChangesAsync(cancellationToken);

                return(new Unit {
                });
            }
예제 #2
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var task = await _context.FindAsync <DblDip.Core.Models.Task>(request.TaskId);

                task.Complete(_dateTime.UtcNow);

                _context.Add(task);

                await _context.SaveChangesAsync(cancellationToken);

                return(new());
            }
예제 #3
0
        public static async System.Threading.Tasks.Task <ICollection <DigitalAsset> > Upload(IHttpContextAccessor httpContextAccessor, IDblDipDbContext context, CancellationToken cancellationToken)
        {
            var httpContext        = httpContextAccessor.HttpContext;
            var defaultFormOptions = new FormOptions();
            var digitalAssets      = new List <DigitalAsset>();

            if (!MultipartRequestHelper.IsMultipartContentType(httpContext.Request.ContentType))
            {
                throw new Exception($"Expected a multipart request, but got {httpContext.Request.ContentType}");
            }

            var mediaTypeHeaderValue = MediaTypeHeaderValue.Parse(httpContext.Request.ContentType);

            var boundary = MultipartRequestHelper.GetBoundary(
                mediaTypeHeaderValue,
                defaultFormOptions.MultipartBoundaryLengthLimit);

            var reader = new MultipartReader(boundary, httpContext.Request.Body);

            var section = await reader.ReadNextSectionAsync();

            while (section != null)
            {
                var hasContentDispositionHeader = ContentDispositionHeaderValue.TryParse(section.ContentDisposition, out ContentDispositionHeaderValue contentDisposition);

                if (hasContentDispositionHeader)
                {
                    if (MultipartRequestHelper.HasFileContentDisposition(contentDisposition))
                    {
                        using (var targetStream = new MemoryStream())
                        {
                            await section.Body.CopyToAsync(targetStream, cancellationToken);

                            var name        = $"{contentDisposition.FileName}".Trim(new char[] { '"' }).Replace("&", "and");
                            var bytes       = StreamHelper.ReadToEnd(targetStream);
                            var contentType = section.ContentType;

                            var digitalAsset = new DigitalAsset(name, bytes, contentType);

                            context.Add(digitalAsset);

                            digitalAssets.Add(digitalAsset);
                        }
                    }
                }

                section = await reader.ReadNextSectionAsync(cancellationToken);
            }

            await context.SaveChangesAsync(cancellationToken);

            return(digitalAssets);
        }
예제 #4
0
            public async Task <Unit> Handle(Request request, CancellationToken cancellationToken)
            {
                var consultation = await _context.FindAsync <Consultation>(request.ConsultationId);

                consultation.Complete(_dateTime.UtcNow);

                _context.Add(consultation);

                await _context.SaveChangesAsync(cancellationToken);

                return(new());
            }
예제 #5
0
        private async Task <IAggregateRoot> GetAggregateAsync(Type type, Guid streamId)
        {
            var aggregate = _inMemoryAggregates.SingleOrDefault(x => x.Key == streamId).Value;

            aggregate ??= (await _context.FindAsync(type, streamId)) as IAggregateRoot;

            if (aggregate == null)
            {
                aggregate = GetUninitializedObject(type) as IAggregateRoot;

                _ = _context.Add(aggregate);
            }

            if (!_inMemoryAggregates.Any(x => x.Key == streamId))
            {
                _inMemoryAggregates.Add(streamId, aggregate);
            }

            return(aggregate);
        }
예제 #6
0
            public async Task <ResponseBase> Handle(Request request, CancellationToken cancellationToken)
            {
                var user = await _context.FindAsync <User>(new Guid(_httpContextAccessor.HttpContext.User.FindFirst(Constants.ClaimTypes.UserId).Value));

                var profile = await _context.FindAsync <Profile>(request.ProfileId);

                var account = await _context.FindAsync <Account>(profile.AccountId);

                if (account.UserId != user.UserId)
                {
                    throw new Exception("Security Exception");
                }

                account.SetDefaultProfileId(request.ProfileId);

                _context.Add(account);

                await _context.SaveChangesAsync(cancellationToken);

                return(new ());
            }