public async Task ReceiveAsync(AuthenticationTokenReceiveContext context) { string header = context.OwinContext.Request.Headers["Authorization"]; context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); var token = Uri.UnescapeDataString(context.Token); var tokenIdHashed = HashTokenId(token); using (EntityFrameworkContext efContext = new EntityFrameworkContext()) { var refreshToken = efContext.RefreshTokens.SingleOrDefault(rt => rt.id == tokenIdHashed); //&& rt.clientId == "" if (refreshToken != null) { efContext.RefreshTokens.Remove(refreshToken); efContext.SaveChanges(); context.DeserializeTicket(refreshToken.protectedTicket); } else { context.Response.StatusCode = 400; context.Response.ContentType = "application/json"; context.Response.ReasonPhrase = "invalid token"; return; } } }
public void EntityFramework_ConcurrentlyUpdateTheSameRecord_DbUpdateConcurrencyExceptionShouldBeThrown() { //arrange var newRecordId = CreateNewEntityFrameworkRecord(); using (var context1 = new EntityFrameworkContext()) { var product1 = context1.Products.First(p => p.Id == newRecordId); product1.Price = 3; using (var context2 = new EntityFrameworkContext()) { var product2 = context2.Products.First(p => p.Id == newRecordId); product2.Price = 2; context2.SaveChanges(); } try { context1.SaveChanges(); } //assert catch (DbUpdateConcurrencyException exception) { System.Diagnostics.Trace.WriteLine(exception.ToString()); return; } } //We reached end of the test...it means that we assumed incorrect behaviour Assert.Fail(); }
public SparePartList GetList(SparePartFilter filter) { using (EntityFrameworkContext context = new EntityFrameworkContext()) { SparePartList list = new SparePartList(); var spareParts = context.SpareParts.Include(x => x.Mark).Where(x => x.Name.ToUpper().Contains(filter.NameFilter)); if (filter.MarkIds.Length > 0) { spareParts = spareParts.Where(x => filter.MarkIds.Contains(x.MarkId)); } list.PagesCount = (int)Math.Ceiling(spareParts.Count() / (double)filter.PageSize); if (filter.Sort > 0) { if ((int)filter.Sort % 2 == 0) { spareParts = spareParts.OrderBy(x => SortFunction[(int)filter.Sort / 2](x)); } else { spareParts = spareParts.OrderByDescending(x => SortFunction[(int)filter.Sort / 2 + 1](x)); } } list.SpareParts = spareParts.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList(); return(list); } }
public SparePart GetById(int id) { using (EntityFrameworkContext context = new EntityFrameworkContext()) { return(context.SpareParts.Find(id)); } }
public User FindByCredentials(string username, string password) { using (EntityFrameworkContext context = new EntityFrameworkContext()) { return(new User()); } }
public IEnumerable <string> Get() { EntityFrameworkContext context = new EntityFrameworkContext(); var test = context.Models.Include(x => x.Mark); return(test.Select(x => x.Mark.Name + " " + x.Name + "!"));//test.Select(x=>x.Mark.Name + " " + x.Name); }
public Mark GetById(int id) { using (EntityFrameworkContext context = new EntityFrameworkContext()) { return(context.Marks.Find(id)); } }
public async Task CreateAsync(AuthenticationTokenCreateContext context) { byte[] randomBytes = new byte[16]; rnd.GetBytes(randomBytes); var refreshTokenId = Convert.ToBase64String(randomBytes); var refreshTokenIdHashed = HashTokenId(refreshTokenId); var refreshTokenProperties = new AuthenticationProperties(context.Ticket.Properties.Dictionary) { IssuedUtc = context.Ticket.Properties.IssuedUtc, ExpiresUtc = DateTime.UtcNow.AddYears(1) //DateTime.UtcNow.AddYears(1) }; var refreshTokenTicket = new AuthenticationTicket(context.Ticket.Identity, refreshTokenProperties); using (EntityFrameworkContext efContext = new EntityFrameworkContext()) { Dom.RefreshToken rt = new Dom.RefreshToken() { id = refreshTokenIdHashed, //als Tipp gelesen, dass man diese am besten Hashen sollte //clientId = "", username = context.Ticket.Identity.Name, issuedUtc = refreshTokenProperties.IssuedUtc.Value, expiresUtc = refreshTokenProperties.ExpiresUtc.Value, protectedTicket = context.SerializeTicket() }; efContext.RefreshTokens.Add(rt); efContext.SaveChanges(); } context.SetToken(refreshTokenId); }
public Assignment convert(EntityFrameworkContext context) { var assignment = new Assignment(); AutoMapper.Mapper.CreateMap <AssignmentView, Assignment>(); AutoMapper.Mapper.Map <AssignmentView, Assignment>(this, assignment); if (this.performerIds != null) { foreach (var performer in context.performers.Where(p => this.performerIds.Contains(p.id))) { assignment.performers.Add(performer); } } if (this.timeReportsIds != null) { foreach (var assignmentTimeReport in context.performerTimeReports.Where(a => this.timeReportsIds.Contains(a.id))) { assignment.timeReports.Add(assignmentTimeReport); } } if (this.clientId != null) { assignment.client = context.clients.FirstOrDefault(c => c.id == this.clientId); } return(assignment); }
/// <summary> /// 取得客戶自動機台單一資料 /// </summary> /// <param name="userID">客戶編號</param> /// <param name="autoID">自動機台編號</param> /// <returns>客戶自動機台單一資料</returns> internal AutoMachineData GetAutoMachineData(int userID, int autoID) { using (EntityFrameworkContext db = new EntityFrameworkContext()) { return(db.AutoMachineReport.Where(x => x.UserID == userID && x.AutoID == autoID).FirstOrDefault()); } }
/// <summary> /// 取得客戶自動機台報表 /// </summary> /// <param name="userID">客戶編號</param> /// <returns>客戶自動機台報表</returns> internal IEnumerable <AutoMachineData> GetAutoMachineReport(int userID) { using (EntityFrameworkContext db = new EntityFrameworkContext()) { return(db.AutoMachineReport.Where(x => x.UserID == userID).OrderByDescending(x => x.AutoID).ToList()); } }
public IActionResult UploadImage(int Id) { int resultId = 0; IFormFile uploadedImage = Request.Form.Files.FirstOrDefault(); if (uploadedImage == null || uploadedImage.ContentType.ToLower().StartsWith("image/")) { using (EntityFrameworkContext dbContext = new EntityFrameworkContext()) { MemoryStream ms = new MemoryStream(); uploadedImage.OpenReadStream().CopyTo(ms); //System.Drawing.Image image = System.Drawing.Image.FromStream(ms); Image imageEntity = new Image() { Name = uploadedImage.Name, Data = ms.ToArray(), ContentType = uploadedImage.ContentType }; resultId = dbContext.Images.Add(imageEntity).Entity.Id; dbContext.SaveChanges(); } } return(Ok(resultId)); }
/// <summary> /// 檢查客戶是否擁有自動機台資料 /// </summary> /// <param name="userID">客戶編號</param> /// <param name="autoID">自動機台編號</param> /// <returns></returns> internal bool CheckUserCanDeleteAutoMachineData(int userID, int autoID) { using (EntityFrameworkContext db = new EntityFrameworkContext()) { return(db.AutoMachineReport.Any(x => x.UserID == userID && x.AutoID == autoID)); } }
/// <summary> /// 根據客代取得客戶分數資料 /// </summary> /// <param name="userID">客戶代碼</param> /// <returns>客戶分數資料</returns> public Score GetScoreInfoByUserID(int userID) { using (EntityFrameworkContext db = new EntityFrameworkContext()) { var result = db.Score.Where(s => s.UserID == userID).FirstOrDefault(); return(result); } }
/// <summary> /// 檢查帳號是否已經存在 /// </summary> /// <param name="email">信箱</param> /// <returns></returns> internal User GetAccountInfo(string email) { using (EntityFrameworkContext db = new EntityFrameworkContext()) { var result = db.User.Where(s => s.Email == email).FirstOrDefault(); return(result); } }
public EntityFrameworkContext Get() { if (dataContext == null) { dataContext = new EntityFrameworkContext(); } return(dataContext); }
public void Delete(int id) { using (EntityFrameworkContext context = new EntityFrameworkContext()) { context.Marks.Remove(context.Marks.Find(id)); context.SaveChanges(); } }
public Knowledge convert(EntityFrameworkContext context) { var output = new Knowledge(); Mapper.CreateMap <KnowledgeView, Knowledge>(); Mapper.Map <KnowledgeView, Knowledge>(this, output); return(output); }
public Customer convert(EntityFrameworkContext context) { var output = new Customer(); Mapper.CreateMap<CustomerView, Customer>(); Mapper.Map<CustomerView, Customer>(this, output); return output; }
public void DeleteSparePart(int id) { using (EntityFrameworkContext context = new EntityFrameworkContext()) { var SparePart = context.SpareParts.Find(id); context.SpareParts.Remove(SparePart); context.SaveChanges(); } }
public SparePart SaveSparePart(SparePart input) { using (EntityFrameworkContext context = new EntityFrameworkContext()) { var resut = context.SpareParts.Add(input); context.SaveChanges(); return(resut.Entity); } }
public PerformerTimeReport convert(EntityFrameworkContext context) { var assignmentTimeReport = new PerformerTimeReport(); AutoMapper.Mapper.CreateMap <PerformerTimeReportView, PerformerTimeReport>(); AutoMapper.Mapper.Map <PerformerTimeReportView, PerformerTimeReport>(this, assignmentTimeReport); return(assignmentTimeReport); }
public PerformerTimeFree convert(EntityFrameworkContext context) { var output = new PerformerTimeFree(); Mapper.CreateMap <PerformerTimeFreeView, PerformerTimeFree>(); Mapper.Map <PerformerTimeFreeView, PerformerTimeFree>(this, output); return(output); }
public Administrator convert(EntityFrameworkContext context) { var output = new Administrator(); Mapper.CreateMap<AdministratorView, Administrator>(); Mapper.Map<AdministratorView, Administrator>(this, output); return output; }
public Customer convert(EntityFrameworkContext context) { var output = new Customer(); Mapper.CreateMap <CustomerView, Customer>(); Mapper.Map <CustomerView, Customer>(this, output); return(output); }
public Administrator convert(EntityFrameworkContext context) { var output = new Administrator(); Mapper.CreateMap <AdministratorView, Administrator>(); Mapper.Map <AdministratorView, Administrator>(this, output); return(output); }
public Role AddRole(Role role) { using (EntityFrameworkContext context = new EntityFrameworkContext()) { var result = context.Roles.Add(role); context.SaveChanges(); return(result.Entity); } }
public CustomerCompany convert(EntityFrameworkContext context) { var output = new CustomerCompany(); Mapper.CreateMap <CustomerPrivateView, CustomerPrivate>(); Mapper.Map <CustomerCompanyView, CustomerCompany>(this, output); return(output); }
public Mark[] GetList() { using (EntityFrameworkContext context = new EntityFrameworkContext()) { MarkList list = new MarkList(); var marks = context.Marks; return(marks.ToArray()); } }
public Employee convert(EntityFrameworkContext context) { var output = new Employee(); Mapper.CreateMap <EmployeeView, Employee>(); Mapper.Map <EmployeeView, Employee>(this, output); return(output); }
/// <summary> /// 取得所有客戶的基本資料 /// </summary> /// <returns>客戶基本資料清單</returns> public IEnumerable <User> GetAllUserInfo() { using (EntityFrameworkContext db = new EntityFrameworkContext()) { //return db.User.ToList(); string sql = @"SELECT Seq, UserID, UserName, Mobile, Email, CreatedTime FROM [dbo].[User]"; var result = db.Database.SqlQuery <User>(sql); return(result.ToList()); } }
public MarkList GetList(MarkFilter filter) { using (EntityFrameworkContext context = new EntityFrameworkContext()) { MarkList list = new MarkList(); var marks = context.Marks.Where(x => x.Name.ToUpper().Contains(filter.NameFilter)); list.PagesCount = (int)Math.Ceiling(marks.Count() / (double)filter.PageSize); list.Marks = marks.Skip((filter.PageNumber - 1) * filter.PageSize).Take(filter.PageSize).ToList(); return(list); } }
public Mission convert(EntityFrameworkContext context) { var output = new Mission(); Mapper.CreateMap<MissionView, Mission>(); Mapper.Map<MissionView, Mission>(this, output); output.employee = this.employeeId == null ? null : context.employees.FirstOrDefault(e => e.id == this.employeeId); output.customer = this.customerId == null ? null : context.customers.FirstOrDefault(c => c.id == this.customerId); return output; }
public OperationResult ChangeEmployee(Model.Employee model) { using (IUnitOfWork unitofwork = new EntityFrameworkContext()) { IEmployeeRepository employeeRepository = new EmployeeRepository(unitofwork); var employee = employeeRepository.GetEntity.Where(m => m.UserName == model.UserName || m.Email == model.Email).FirstOrDefault(); employee.RealName = model.RealName; employeeRepository.Update(employee); int count = unitofwork.Commit(); return new OperationResult(OperationResultType.Success, count.ToString()); } }
public OperationResult CreateRole(Model.Role model) { using (IUnitOfWork unitofwork = new EntityFrameworkContext()) { IRoleRepository roleRepository = new RoleRepository(unitofwork); if (roleRepository.GetEntity.Count(m => m.RoleName == model.RoleName) <= 0) { roleRepository.Insert(model); unitofwork.Commit(); return new OperationResult(OperationResultType.Success, "角色添加成功."); } return new OperationResult(OperationResultType.NoChanged, "角色名已存在."); } }
public OperationResult CreateEmployee(Model.Employee model) { using (IUnitOfWork unitofwork = new EntityFrameworkContext()) { IEmployeeRepository employeeRepository = new EmployeeRepository(unitofwork); if (!employeeRepository.ExistsUserName(model.UserName)) { employeeRepository.Insert(model); unitofwork.Commit(); return new OperationResult(OperationResultType.Success, "用户注册成功."); } return new OperationResult(OperationResultType.NoChanged, "用户名已存在."); } }
public EmployeesController(EntityFrameworkContext context) { this._context = context; }
public EmployeesController() { this._context = new EntityFrameworkContext(); }
public AssignmentController() { EntityFrameworkContext context = new EntityFrameworkContext(); _db = new EntityFrameworkRepository<Assignment>(context); }
public CustomersPrivateController(EntityFrameworkContext context) { this._context = context; }
public ClientController() { EntityFrameworkContext context = new EntityFrameworkContext(); context.Configuration.ProxyCreationEnabled = false; _db = new EntityFrameworkRepository<Client>(context); }
public AdministratorsController(EntityFrameworkContext context) { this._context = context; }
public CustomersPrivateController() { this._context = new EntityFrameworkContext(); }
public MissionsController(EntityFrameworkContext context) { this._context = context; }
public MissionsController() { this._context = new EntityFrameworkContext(); }
public AdministratorsController() { this._context = new EntityFrameworkContext(); }
public CustomersCompanyController(EntityFrameworkContext context) { this._context = context; }
public CustomersCompanyController() { this._context = new EntityFrameworkContext(); }
public CustomerCompany convert(EntityFrameworkContext context) { var output = new CustomerCompany(); Mapper.CreateMap<CustomerPrivateView, CustomerPrivate>(); Mapper.Map<CustomerCompanyView, CustomerCompany>(this, output); return output; }
public Employee convert(EntityFrameworkContext context) { var output = new Employee(); Mapper.CreateMap<EmployeeView, Employee>(); Mapper.Map<EmployeeView, Employee>(this, output); return output; }