public bool Create(Usuario usuario, ControleAcesso controleAcesso) { DbSet <Usuario> dsUsuario = null; using (_context) { using (var dbContextTransaction = _context.Database.BeginTransaction()) { try { dsUsuario = _context.Set <Usuario>(); dsUsuario.Add(usuario); _context.SaveChanges(); string sql = "INSERT INTO[dbo].[ControleAcesso] ([login], [senha], [idUsuario]) VALUES (@login, @senha, @idUsuario)"; _context.Database.ExecuteSqlCommand(sql, new SqlParameter("@login", controleAcesso.Login), new SqlParameter("@senha", controleAcesso.Senha), new SqlParameter("@idUsuario", usuario.Id.Value)); dbContextTransaction.Commit(); return(true); } catch (Exception) { dbContextTransaction.Rollback(); } } } return(false); }
private void ProcessResourceType <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType>(string ResourceName) where ResCurrentType : ResourceCurrentBase <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> where ResIndexStringType : ResourceIndexString <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> where ResIndexTokenType : ResourceIndexToken <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> where ResIndexUriType : ResourceIndexUri <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> where ResIndexReferenceType : ResourceIndexReference <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> where ResIndexQuantityType : ResourceIndexQuantity <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> where ResIndexDateTimeType : ResourceIndexDateTime <ResCurrentType, ResIndexStringType, ResIndexTokenType, ResIndexUriType, ResIndexReferenceType, ResIndexQuantityType, ResIndexDateTimeType> { try { Hl7.Fhir.Serialization.FhirXmlSerializer FhirXmlSerializer = new Hl7.Fhir.Serialization.FhirXmlSerializer(); bool Running = true; while (Running) { IPyroDbContext context = new MsSqlContext(); var Query = context.Set <ResCurrentType>().Where(x => x.XmlBlob != null && x.IsDeleted == false && x.Resource == null).Take(200).ToList(); if (Query == null || Query.Count == 0) { Running = false; } else { foreach (var ResourceEntity in Query) { if (!string.IsNullOrWhiteSpace(ResourceEntity.XmlBlob)) { Resource Res = Common.Tools.FhirResourceSerializationSupport.DeSerializeFromXml(ResourceEntity.XmlBlob); byte[] ResBytes = FhirXmlSerializer.SerializeToBytes(Res); ResourceEntity.Resource = Common.Tools.GZip.GZipper.Compress(ResBytes); ResourceEntity.XmlBlob = null; context.Set <ResCurrentType>().AddOrUpdate(ResourceEntity); } } context.SaveChanges(); context.Dispose(); } } } catch (Exception Exec) { throw new Exception($"The Resource Type {ResourceName}", Exec); } }
/// <summary> /// 返回单科成绩数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="page"></param> /// <param name="limit"></param> /// <param name="StudentsInfoId"></param> /// <returns></returns> public IEnumerable <QueryCourseScore> QueryCourseScores <T>(int page, int limit, string StudentsInfoId) where T : BaseCourse { //Dictionary<int, IList<QueryCourseScore> > dic = new Dictionary<int, IList<QueryCourseScore>>(); //var count = _msSqlContext.Set<T>().Where(scores => scores.StudentInfoId == StudentsInfoId).Count(); var datas = _msSqlContext.Set <T>() .Where(scores => scores.StudentInfoId == StudentsInfoId) .Skip(limit * (page - 1)) .Take(limit) .Select(data => new QueryCourseScore() { Id = data.Id, Name = data.Name, DateTime = data.DateTime, Score = data.Score }) .ToList(); return(datas); }
public virtual async Task <TEntity> Get(int id) { return(await _context.Set <TEntity>().FindAsync(id)); }
public async Task CreateAsync(TModel entity) { await _context.Set <TModel>().AddAsync(entity); }
public GenericRepositorio() { _context = new MsSqlContext(); dataSet = _context.Set <T>(); }
public void Insert(T obj) { context.Set <T>().Add(obj); context.SaveChanges(); }