示例#1
0
        public async Task <bool> UpdateStudentAsync(StudentDto studentDto, string username /*, String[] includeNavigations, params Expression<Func<Student, bool>>[] filters*/)
        {
            OnUpdate(studentDto, username);

            // Get Student
            var entity = EntityQuery(_context, StudentDto.IncludeNavigations())
                         .FirstOrDefault(x => x.Id == studentDto.Id);

            if (entity != null)
            {
                entity = StudentDto.ToStudentFunc(entity, studentDto);

                ToEntity(ref entity, studentDto);
                //entity.UpdateUser = entity.LastActivityUser = username;
                //entity.UpdateDateTime = entity.LastActivityDateTime = DateTime.UtcNow;
                entity.EditTracker(username);

                OnBeforeUpdate(entity, username);
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    // _context.Entry(entity).State = EntityState.Detached;
                    throw new Exception("Update error", ex);
                }
                finally
                {
                    // _context.Entry(entity).State = EntityState.Detached;
                }
                OnAfterUpdate(entity, username);
            }
            else
            {
                return(false);
            }

            return(true);
        }