コード例 #1
0
 public JsonCamelCaseResult GetDeparturesByVariantId(int variantId)
 {
     using (BackendContext db = new BackendContext())
     {
         return(new JsonCamelCaseResult(db.Departures.Where(d => d.Variant.Id == variantId).ToList()));
     }
 }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: TaskBiz.cs プロジェクト: cool-db/Backend
        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));
            }
        }
コード例 #4
0
 public JsonCamelCaseResult GetStop(int stopId)
 {
     using (BackendContext db = new BackendContext())
     {
         return(new JsonCamelCaseResult(db.Stops.Single(s => s.Id == stopId)));
     }
 }
コード例 #5
0
 public AuthController(BackendContext context, UserManager <User> userManager,
                       SignInManager <User> signInManager)
 {
     _context       = context;
     _userManager   = userManager;
     _signInManager = signInManager;
 }
コード例 #6
0
        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()));
        }
コード例 #7
0
ファイル: FileBiz.cs プロジェクト: cool-db/Backend
        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));
            }
        }
コード例 #8
0
 public JsonCamelCaseResult ListStops()
 {
     using (BackendContext db = new BackendContext())
     {
         return(new JsonCamelCaseResult(db.Stops.OrderBy(s => s.Name).ToList()));
     }
 }
コード例 #9
0
 /// <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();
 }
コード例 #10
0
ファイル: ScheduleBiz.cs プロジェクト: cool-db/Backend
        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));
            }
        }
コード例 #11
0
ファイル: TaskBiz.cs プロジェクト: cool-db/Backend
        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));
            }
        }
コード例 #12
0
        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));
            }
        }
コード例 #13
0
        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.");
        }
コード例 #14
0
ファイル: UserBiz.cs プロジェクト: cool-db/Backend
        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));
            }
        }
コード例 #15
0
        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));
            }
        }
コード例 #16
0
ファイル: UserBiz.cs プロジェクト: cool-db/Backend
        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));
            }
        }
コード例 #17
0
ファイル: UserBiz.cs プロジェクト: cool-db/Backend
        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));
            }
        }
コード例 #18
0
ファイル: UserBiz.cs プロジェクト: cool-db/Backend
        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));
            }
        }
コード例 #19
0
ファイル: Startup.cs プロジェクト: pwhitdog/ChatterSolution
        // 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();
        }
コード例 #20
0
        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));
            }
        }
コード例 #21
0
        // 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();
            });
        }
コード例 #22
0
ファイル: FileBiz.cs プロジェクト: cool-db/Backend
        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));
            }
        }
コード例 #23
0
ファイル: TaskBiz.cs プロジェクト: cool-db/Backend
        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));
            }
        }
コード例 #24
0
ファイル: Service.cs プロジェクト: ProyectoISoftware/Proyecto
        public void Add(Persona persona)
        {
            // Guardo la Persona en el Backend
            BackendContext.Personas.Add(persona);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
コード例 #25
0
 public JsonCamelCaseResult GetVariant(int variantId)
 {
     using (BackendContext db = new BackendContext())
     {
         db.Configuration.LazyLoadingEnabled = false;
         return(new JsonCamelCaseResult(db.Variants.Single(v => v.Id == variantId)));
     }
 }
コード例 #26
0
ファイル: Service.cs プロジェクト: ProyectoISoftware/Proyecto
        public void Add(Documento documento)
        {
            // Guardo la Persona en el Backend
            BackendContext.Documento.Add(documento);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
コード例 #27
0
        public void AddAutor(Autor autor)
        {
            // Guardo el Autor en el Backend
            BackendContext.Autores.Add(autor);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
コード例 #28
0
        public void AddPublicaciones(Publicacion publicacion)
        {
            // Guardo la Publicacion en el Backend
            BackendContext.Publicaciones.Add(publicacion);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
コード例 #29
0
        public void AddEstadoPostulacion(EstadoDePostulacion estadoPostulacion)
        {
            // Guardo el paper en el Backend
            BackendContext.EstadosdePostulaciones.Add(estadoPostulacion);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
コード例 #30
0
        public void AddPaper(Paper paper)
        {
            // Guardo el paper en el Backend
            BackendContext.Papers.Add(paper);

            // Guardo los cambios
            BackendContext.SaveChanges();
        }
コード例 #31
0
        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;
        }