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()); }
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); }
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()); }
public async Task Handle(EventStoreChanged notification, CancellationToken cancellationToken) { foreach (var storedEvent in notification.Events) { var type = Type.GetType(storedEvent.AggregateDotNetType); var entity = await GetAggregateAsync(type, storedEvent.StreamId); entity.Apply(JsonConvert.DeserializeObject(storedEvent.Data, Type.GetType(storedEvent.DotNetType)) as IEvent); } await _context.SaveChangesAsync(cancellationToken); }
public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var photographer = await _context.FindAsync <Photographer>(request.PhotographerId); var digitalAsset = (await DigitalAsset.Upload(_httpContextAccessor, _context, cancellationToken)).Single(); photographer.UpdateAvatar(digitalAsset.DigitalAssetId); await _context.SaveChangesAsync(cancellationToken); return(new Response() { DigitalAssetId = digitalAsset.DigitalAssetId }); }
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 { }); }
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 ()); }