public JsonCamelCaseResult GetDeparturesByVariantId(int variantId) { using (BackendContext db = new BackendContext()) { return(new JsonCamelCaseResult(db.Departures.Where(d => d.Variant.Id == variantId).ToList())); } }
public static bool CheckPermission(int projectId, int userId, bool isOwner, OperationType type) { if (isOwner) { return(true); } using (var context = new BackendContext()) { var project = (from p in context.Projects where p.Id == projectId select p).FirstOrDefault(); var permission = (from p in project.UserPermissons where p.UserId == userId select p).FirstOrDefault().Permission; switch (type) { case OperationType.GET: case OperationType.POST: case OperationType.SPECIAL: return(true); case OperationType.DELETE: case OperationType.PUT: return(permission != Permission.Participant); } } return(false); }
public static object GetCommentList(int taskId) { using (var context = new BackendContext()) { var queryTask = context.Tasks.Where(task => task.Id == taskId); if (!queryTask.Any()) { return(Helper.Error(404, "任务不存在")); } var theTask = queryTask.Single(); var comments = (from comment in theTask.Comments select new { id = comment.Id, content = comment.Content, userId = comment.UserId, taskId = comment.TaskId }).ToArray(); var data = new { comments }; return(Helper.BuildResult(data)); } }
public JsonCamelCaseResult GetStop(int stopId) { using (BackendContext db = new BackendContext()) { return(new JsonCamelCaseResult(db.Stops.Single(s => s.Id == stopId))); } }
public AuthController(BackendContext context, UserManager <User> userManager, SignInManager <User> signInManager) { _context = context; _userManager = userManager; _signInManager = signInManager; }
internal ShaderModel GetShaderModel(string setName) { BackendContext context = GetContext(setName); foreach (ResourceDefinition rd in context.Resources .Where(rd => rd.ResourceKind == ShaderResourceKind.Uniform || rd.ResourceKind == ShaderResourceKind.RWStructuredBuffer || rd.ResourceKind == ShaderResourceKind.StructuredBuffer)) { ForceTypeDiscovery(setName, rd.ValueType); } // HACK: Discover all field structure types. foreach (StructureDefinition sd in context.Structures.ToArray()) { foreach (FieldDefinition fd in sd.Fields) { ForceTypeDiscovery(setName, fd.Type); } } // HACK: Discover all method input structures. foreach (ShaderFunctionAndBlockSyntax sf in context.Functions.ToArray()) { if (sf.Function.IsEntryPoint) { GetCode(setName, sf.Function); } } return(new ShaderModel( context.Structures.ToArray(), context.Resources.ToArray(), context.Functions.Select(sfabs => sfabs.Function).ToArray())); }
public static object PostFile(object json, HttpPostedFile file) { var body = Helper.Decode(json); var userId = int.Parse(body["userId"]); var projectId = int.Parse(body["projectId"]); var name = body["name"]; var stream = file.InputStream; var bytes = new byte[stream.Length]; stream.Read(bytes, 0, bytes.Length); using (var context = new BackendContext()) { var newFile = new File() { Name = name, Content = bytes, UploadTime = DateTime.Now, UserId = userId, ProjectId = projectId }; context.File.Add(newFile); context.SaveChanges(); var result = new { id = newFile.Id, name = newFile.Name }; return(Helper.BuildResult(result)); } }
public JsonCamelCaseResult ListStops() { using (BackendContext db = new BackendContext()) { return(new JsonCamelCaseResult(db.Stops.OrderBy(s => s.Name).ToList())); } }
/// <summary> /// Servicio que agrega un autor a un paper. /// </summary> /// <param name="IdentificadorPaper"></param> /// <param name="autor"></param> /// <returns>Lista de Personas</returns> public void AddAutorToPaper(string IdentificadorPaper, Autor autor) { BackendContext.Papers .Where(p => p.IdentificadorPaper == IdentificadorPaper) .First().Autores.Add(autor); BackendContext.SaveChanges(); }
public static object GetScheduleList(int projectId) { using (var context = new BackendContext()) { if (!context.Projects.Any(p => p.Id == projectId)) { return(Helper.Error(404, "项目不存在")); } var scheduleList = (from schedule in context.Schedules where schedule.ProjectId == projectId select new { scheduleId = schedule.Id, scheduleName = schedule.Name, startTime = schedule.StartTime, endTime = schedule.EndTime, repeatDaily = schedule.RepeatDaily, repeatWeekly = schedule.RepeatWeekly }).ToArray(); var data = new { scheduleList }; return(Helper.BuildResult(data)); } }
public static object GetMemberList(int taskId) { using (var context = new BackendContext()) { var queryTask = context.Tasks.Where(task => task.Id == taskId); if (!queryTask.Any()) { return(Helper.Error(404, "任务不存在")); } var theTask = queryTask.Single(); var members = (from user in theTask.Users select new { id = user.Id, name = user.UserInfo.Name }).ToArray(); var data = new { members }; return(Helper.BuildResult(data)); } }
public static object GetMemberList(int projectId) { using (var context = new BackendContext()) { var queryProject = context.Projects.Where(project => project.Id == projectId); if (!queryProject.Any()) { return(Helper.Error(404, "项目不存在")); } var theProject = queryProject.Single(); var members = (from theProjectUser in theProject.Users select new { id = theProjectUser.Id, name = theProjectUser.UserInfo.Name, permission = theProjectUser.UserPermissons.Single(p => p.ProjectId == projectId).Permission, email = theProjectUser.Email, avatar = theProjectUser.UserInfo.Avatar }).ToArray(); var data = new { members }; return(Helper.BuildResult(data)); } }
public MainServiceTest() { // Logger Factory ILoggerFactory loggerFactory = new LoggerFactory().AddConsole().AddDebug(); Logger = loggerFactory.CreateLogger <MainServiceTest>(); Logger.LogInformation("Initializing Test .."); // SQLite en memoria var connection = new SqliteConnection("DataSource=:memory:"); connection.Open(); // Opciones de inicializacion del BackendContext var options = new DbContextOptionsBuilder <BackendContext>() .UseSqlite(connection) .Options; // inicializacion del BackendContext BackendContext backend = new BackendContext(options); // Crear la base de datos backend.Database.EnsureCreated(); // Servicio a probar Service = new MainService(backend, loggerFactory); Logger.LogInformation("Initialize Test ok."); }
public static object Login(object json) { //获取输入 var body = Helper.Decode(json); var email = body["email"]; var password = body["password"]; using (var context = new BackendContext()) { //查询&验证 var query = context.Users.Where(user => user.Email == email && user.Password == password); if (!query.Any()) { return(Helper.Error(401, "邮箱或密码错误")); } //修改&保存 var theUser = query.Single(); theUser.GenerateToken(); context.SaveChanges(); //返回 var data = new { id = theUser.Id, token = theUser.Token, name = theUser.UserInfo.Name, avatar = theUser.UserInfo.Avatar }; return(Helper.BuildResult(data)); } }
public static object GetList(int userId) { using (var context = new BackendContext()) { var queryUser = context.Users.Where(user => user.Id == userId); if (!queryUser.Any()) { return(Helper.Error(401, "不存在该用户")); } var theUser = queryUser.Single(); var projects = (from project in theUser.Projects select new { id = project.Id, name = project.Name, description = project.Description, ownerId = project.OwnerId }).ToArray(); var data = new { projects }; return(Helper.BuildResult(data)); } }
public static object SetAvatar(object json) { var body = Helper.Decode(json); var id = int.Parse(body["id"]); var avatar = body["avatar"]; using (var context = new BackendContext()) { var query = context.Users.Where(user => user.Id == id); if (!query.Any()) { return(Helper.Error(404, "该用户不存在")); } var theUser = query.Single(); var theInfo = theUser.UserInfo; theInfo.Avatar = "data:image/png;base64," + avatar; context.SaveChanges(); var data = new { id = theUser.Id, name = theInfo.Name, avatar = theInfo.Avatar }; return(Helper.BuildResult(data)); } }
public static object ChangePassword(object json) { var body = Helper.Decode(json); var id = int.Parse(body["userId"]); var passwordFrom = body["passwordFrom"]; var passwordTo = body["passwordTo"]; using (var context = new BackendContext()) { var query = context.Users.Where(user => user.Id == id && user.Password == passwordFrom); if (!query.Any()) { return(Helper.Error(401, "密码错误")); } var theUser = query.Single(); theUser.Password = passwordTo; theUser.GenerateToken(); context.SaveChanges(); var data = new { token = theUser.Token }; return(Helper.BuildResult(data)); } }
public static object GetInfo(int id) { using (var context = new BackendContext()) { var query = context.Users.Where(user => user.Id == id); if (!query.Any()) { return(Helper.Error(404, "用户不存在")); } var theUser = query.Single(); var data = new { id = theUser.Id, email = theUser.Email, name = theUser.UserInfo.Name, address = theUser.UserInfo.Address, gender = theUser.UserInfo.Gender, phonenumber = theUser.UserInfo.Phonenumber, job = theUser.UserInfo.Job, website = theUser.UserInfo.Website, birthday = theUser.UserInfo.Birthday, avatar = theUser.UserInfo.Avatar }; return(Helper.BuildResult(data)); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, BackendContext dbContext, UserManager <IdentityUser> userManager) { app.UseCors(builder => { builder.WithOrigins("https://localhost:5003") .AllowAnyHeader().AllowAnyMethod().AllowCredentials(); }); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseRouting(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); // var isCreated = dbContext.Database.EnsureCreated(); // if (isCreated) return; // var dbInitializer = new DbInitializer(userManager); // dbInitializer.Initialize(dbContext).Wait(); }
public static object DeleteProject(object json) { var body = Helper.Decode(json); var projectId = int.Parse(body["projectId"]); var ownerId = int.Parse(body["ownerId"]); using (var context = new BackendContext()) { var queryUser = context.Users.Where(user => user.Id == ownerId); if (!queryUser.Any()) { return(Helper.Error(404, "用户不存在")); } var queryProject = context.Projects.Where(project => project.Id == projectId); if (!queryProject.Any()) { return(Helper.Error(404, "项目不存在")); } var theProject = queryProject.Single(); if (theProject.OwnerId != ownerId) { return(Helper.Error(401, "该用户未拥有该项目")); } context.Projects.Remove(theProject); context.SaveChanges(); return(Helper.BuildResult(null)); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, BackendContext db) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); c.RoutePrefix = string.Empty; //Hint set swagger in root! }); app.UseHttpsRedirection(); app.UseRouting(); app.UseAuthorization(); //Do "Update-Database" runtime. Requires an "Add-Migration" done first db.Database.Migrate(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }
public static object DeleteFile(object json) { var body = Helper.Decode(json); var fileId = int.Parse(body["fileId"]); var userId = int.Parse(body["userId"]); using (var context = new BackendContext()) { var queryFile = context.File.Where(file => file.Id == fileId); if (!queryFile.Any()) { return(Helper.Error(404, "未找到文件")); } var queryUser = context.Users.Where(u => u.Id == userId); if (!queryUser.Any()) { return(Helper.Error(404, "未找到用户")); } var theFile = queryFile.Single(); if (theFile.Project.Users.All(u => u.Id != userId)) { return(Helper.Error(403, "用户未参加该项目")); } if (theFile.UserId != userId && theFile.Project.UserPermissons.Single(p => p.UserId == userId).Permission == Permission.Participant) { return(Helper.Error(401, "权限不足")); } context.File.Remove(theFile); context.SaveChanges(); return(Helper.BuildResult(null)); } }
public static object CreateSubTask(object json) { var body = Helper.DecodeToObject(json); using (var context = new BackendContext()) { var content = body["subtaskContent"].ToString(); var taskId = int.Parse(body["taskId"].ToString()); var userId = int.Parse(body["userId"].ToString()); var query = context.Users.Where(user => user.Id == userId); if (!query.Any()) { return(Helper.Error(401, "userId不存在")); } var queryTask = context.Tasks.Where(task => task.Id == taskId); if (!queryTask.Any()) { return(Helper.Error(404, "任务不存在")); } var theTask = queryTask.Single(); var flag = userId == theTask.OwnerId; // if (!Helper.CheckPermission(theTask.Progress.ProjectId, userId, flag, OperationType.POST)) // { // return Helper.Error(401, "无权限"); // } var newSubTask = new Subtask { Content = content, State = false, UserId = userId, TaskId = theTask.Id }; newSubTask.User = query.Single(); context.Subtasks.Add(newSubTask); theTask.Subtasks.Add(newSubTask); context.SaveChanges(); RecordTaskOperation(userId, taskId, "创建了子任务:" + newSubTask.Content); var data = new { subtaskId = newSubTask.Id, subtaskContent = newSubTask.Content, taskId = newSubTask.TaskId, state = newSubTask.State, executorId = newSubTask.UserId }; return(Helper.BuildResult(data)); } }
public void Add(Persona persona) { // Guardo la Persona en el Backend BackendContext.Personas.Add(persona); // Guardo los cambios BackendContext.SaveChanges(); }
public JsonCamelCaseResult GetVariant(int variantId) { using (BackendContext db = new BackendContext()) { db.Configuration.LazyLoadingEnabled = false; return(new JsonCamelCaseResult(db.Variants.Single(v => v.Id == variantId))); } }
public void Add(Documento documento) { // Guardo la Persona en el Backend BackendContext.Documento.Add(documento); // Guardo los cambios BackendContext.SaveChanges(); }
public void AddAutor(Autor autor) { // Guardo el Autor en el Backend BackendContext.Autores.Add(autor); // Guardo los cambios BackendContext.SaveChanges(); }
public void AddPublicaciones(Publicacion publicacion) { // Guardo la Publicacion en el Backend BackendContext.Publicaciones.Add(publicacion); // Guardo los cambios BackendContext.SaveChanges(); }
public void AddEstadoPostulacion(EstadoDePostulacion estadoPostulacion) { // Guardo el paper en el Backend BackendContext.EstadosdePostulaciones.Add(estadoPostulacion); // Guardo los cambios BackendContext.SaveChanges(); }
public void AddPaper(Paper paper) { // Guardo el paper en el Backend BackendContext.Papers.Add(paper); // Guardo los cambios BackendContext.SaveChanges(); }
public BackendContext Load(BackendConnection connection) { var contextType = ContextType.SMA; if (connection.IsAzure) contextType = ContextType.Azure; else if (connection.IsAzureRM) contextType = ContextType.AzureRM; var existingBackend = _backendContexts.FirstOrDefault(c => c.ID == connection.Id); if (existingBackend != null) return existingBackend; var environment = IoC.Get<EnvironmentExplorerViewModel>(); var backend = new BackendContext(contextType, connection); _backendContexts.Add(backend); Execute.OnUIThread(() => environment.Items.Add(backend.GetStructure())); backend.OnLoaded += OnBackendReady; return backend; }