예제 #1
0
        public async Task <int> SaveAsync(BL.Role entity)
        {
            try
            {
                if (entity == null)
                {
                    return(0);
                }

                using (var context = _contextFactory.GetProductContext())
                {
                    var entityModel = await context
                                      .Roles
                                      .FirstOrDefaultAsync(item => item.Id.Equals(entity.Id));

                    if (entityModel == null)
                    {
                        entityModel = new DA.Role();
                        MapForUpdateEntity(entity, entityModel);
                        await context.Roles.AddAsync(entityModel);
                    }
                    else
                    {
                        MapForUpdateEntity(entity, entityModel);
                    }

                    context.SaveChanges();
                    return(entityModel.Id);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #2
0
        public async Task SaveAsync(Role entity)
        {
            try
            {
                if (entity == null)
                {
                    return;
                }

                using (var timeLineContext = _contextFactory.GetTimeLineContext())
                {
                    var entityModel = await timeLineContext
                                      .Roles
                                      .FirstOrDefaultAsync(item => item.Id.Equals(entity.Id));

                    if (entityModel == null)
                    {
                        entityModel = new DA.Role();
                        MapForUpdateentity(entity, entityModel);
                        await timeLineContext.Roles.AddAsync(entityModel);
                    }
                    else
                    {
                        MapForUpdateentity(entity, entityModel);
                    }


                    timeLineContext.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
0
 private void MapForUpdateEntity(BL.Role entity, DA.Role daEntity)
 {
     daEntity.Id   = entity.Id;
     daEntity.Name = entity.Name;
 }
예제 #4
0
 private void MapForUpdateentity(Role entity, DA.Role daEntity)
 {
     daEntity.Id = entity.Id;
 }