示例#1
0
        /// <summary>
        /// Saves the or update.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public override async Task <IRole> SaveOrUpdateAsync(IRole entity)
        {
            IRole role = await base.SaveOrUpdateAsync(entity);

            using (CellentContext context = new CellentContext())
            {
                RoleDao roleDao = await context.Roles.FirstOrDefaultAsync(d => d.Id == role.Id);

                await context.SaveChangesAsync();

                role = Mapper.Convert(roleDao);
                return(role);
            }
        }
示例#2
0
        /// <summary>
        /// Saves the or update asynchronous.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <returns></returns>
        public override async Task <IChangeLog> SaveOrUpdateAsync(IChangeLog entity)
        {
            ChangeLogDao dao = Mapper.Convert(entity);

            dao.ChangedAt = DateTime.Now;
            if (dao.ChangedBy == Guid.Empty)
            {
                dao.ChangedBy = CurrentUserId;
            }

            using (CellentContext context = new CellentContext())
            {
                switch (dao.State)
                {
                case Constants.EntityState.Created:
                    dao.CreatedAt = DateTime.Now;
                    if (dao.CreatedBy == Guid.Empty)
                    {
                        dao.CreatedBy = CurrentUserId;
                    }
                    context.Set(dao.GetType()).Add(dao);
                    break;

                case Constants.EntityState.Modified:
                    context.Set(dao.GetType()).Attach(dao);
                    context.Entry(dao).State = EntityState.Modified;
                    break;
                }

                context.Entry(dao.DomainObject).State = EntityState.Unchanged;
                await context.SaveChangesAsync();

                entity = Mapper.Convert(dao);
                EventAggregator.GetEvent <EntityUpdated>().Publish(entity);

                return(entity);
            }
        }