Пример #1
0
        public IActionResult AddUser(int id, [FromBody] User user)
        {
            Project project = gxdb.Projects.SingleOrDefault(u => u.Id == id);

            if (project == null)
            {
                return(NotFound());
            }
            project.UserProjects.Add(new UserProject()
            {
                Project = project, User = user
            });
            gxdb.SaveChanges();
            return(Ok());
        }
Пример #2
0
        public IActionResult UpdateUser(int id, [FromBody] User user)
        {
            if (user == null || user.Id != id)
            {
                return(BadRequest());
            }
            var user1 = gxdb.Users.SingleOrDefault(u => u.Id == id);

            if (user1 == null)
            {
                return(NotFound());
            }

            user1.Name     = user.Name;
            user1.PassWord = user.PassWord;
            gxdb.SaveChanges();

            return(new NoContentResult());
        }
Пример #3
0
        public bool CreateProject(User user, ref Project project)
        {
            if (user == null || project == null)
            {
                throw new ArgumentNullException("Create project:null parameter.");
            }
            using (var transaction = gxDb.Database.BeginTransaction())
            {
                try
                {
                    //project name must be unique
                    string name = project.Name;
                    var    prjs = gxDb.Projects.Where(u => u.Name == name && u.CreatorId == user.Id).ToList();
                    if (prjs.Count != 0)
                    {
                        return(false);
                    }

                    project.Creator = user;
                    //property template:default: ID=1
                    project.PropertyTemplate = gxDb.PropertyTemplates.Single(u => u.Id == 1);

                    gxDb.Projects.Add(project);
                    gxDb.SaveChanges();
                    //creator
                    UserProject userProject = new UserProject
                    {
                        User    = user,
                        Project = project
                    };
                    gxDb.UserProjects.Add(userProject);
                    gxDb.SaveChanges();

                    transaction.Commit();

                    //created project will be active defaultly.
                    SetActiveProject(user, ref project);
                    return(true);
                }

                catch (Exception)
                {
                    throw;
                }
            }
        }
Пример #4
0
 public void AddGeoPoint(Project project, GeoPoint geoPoint)
 {
     project.GeoPoints.Add(geoPoint);
     gxDb.SaveChanges();
 }
Пример #5
0
 public void  AddProperty(GxProperty gxProperty)
 {
     gxDb.GxProperties.Add(gxProperty);
     gxDb.SaveChanges();
 }
Пример #6
0
        public ServiceTest(ITestOutputHelper output)
        {
            this.output = output;

            gxDb            = new GxContextFactory().CreateDbContext(new string[] { "test" });
            userService     = new UserService(gxDb);
            projectService  = new ProjectService(gxDb);
            propertyService = new PropertyService(gxDb);

            // add property
            var data = TemplateConfig.ReadDefaultTemplate();

            propertyService.AddProperties(data);
            //add  template
            var template = new PropertyTemplate()
            {
                Name = "Default"
            };
            //add template-property
            List <Template_Property> template_s = new List <Template_Property>(data.Count);

            foreach (var item in data)
            {
                template_s.Add(new Template_Property()
                {
                    PropertyTemplate = template, GxProperty = item
                });
            }
            template.Template_Properties = template_s;

            gxDb.PropertyTemplates.Add(template);
            gxDb.SaveChanges();

            //add user data
            User[] users = new User[]
            {
                new User()
                {
                    Name = "Jack", PassWord = "******"
                },
                new User()
                {
                    Name = "Andy", PassWord = "******"
                },
                new User()
                {
                    Name = "Frank", PassWord = "******"
                },
                new User()
                {
                    Name = "张山", PassWord = "******"
                }
            };
            foreach (var user in users)
            {
                if (userService.Register(user.Name, user.PassWord))
                {
                    output.WriteLine($"{user.Name}注册成功!");
                }
                else
                {
                    output.WriteLine($"{user.Name}注册失败,用户名已存在!");
                }
            }
            //add project
            User    u       = userService.Login("Jack", "123");
            Project project = new Project()
            {
                Creator = u, Name = "Test Project1"
            };

            project.PropertyTemplate = template;

            userService.CreateProject(u, ref project);
        }