Пример #1
0
        public async Task <BankAccount> SaveAsync(BankAccount domainObjectToSave)
        {
            var entity = Mapper.Map <BankAccountEntity>(domainObjectToSave);

            if (base.IsNew(domainObjectToSave))
            {
                entity.Audit = new EntityFramework.Model.Core.AuditEntity()
                {
                    CreatedBy = UserContextProvider.GetCurrentUser().SignOn,
                    CreatedOn = DateTimeProvider.UtcNow
                };
                DbContext.BankAccounts.Add(entity);
            }
            else
            {
                entity.Audit           = DbContext.AuditTrail.Single(x => x.AuditID == entity.AuditID);
                entity.Audit.UpdatedBy = UserContextProvider.GetCurrentUser().SignOn;
                entity.Audit.UpdatedOn = DateTimeProvider.UtcNow;

                DbContext.BankAccounts.Update(entity);
            }

            await DbContext.SaveChangesAsync().ConfigureAwait(false);

            return(Mapper.Map <BankAccount>(entity));
        }
Пример #2
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            if (!context.ActionArguments.TryGetValue("id", out var id) &&
                !context.ActionArguments.TryGetValue("postId", out id))
            {
                throw new InvalidOperationException();
            }

            var postOwnerInfo = PostsRepository.GetById(id.AsInt(), p => new
            {
                Id = p.OwnerId
            }, false);

            if (postOwnerInfo is null)
            {
                context.Result = new NotFoundResult();
                return;
            }

            if (!UserContextProvider.Get().IsBackend || postOwnerInfo.Id != id.AsInt())
            {
                context.Result = new ForbidResult("You have no access to this post.");
                return;
            }

            await next();
        }
        public async Task <Document> SaveAsync(Document domainObjectToSave)
        {
            var entity = Mapper.Map <DocumentEntity>(domainObjectToSave);

            if (base.IsNew(domainObjectToSave))
            {
                entity.Audit = new EntityFramework.Model.Core.AuditEntity()
                {
                    CreatedBy = UserContextProvider.GetCurrentUser().SignOn,
                    CreatedOn = DateTimeProvider.UtcNow
                };
                DbContext.Documents.Add(entity);
            }
            else
            {
                // TODO: handle audit change
                DbContext.Documents.Update(entity);
            }

            await DbContext.SaveChangesAsync().ConfigureAwait(false);

            return(Mapper.Map <Document>(entity));
        }