Ejemplo n.º 1
0
 public List<TopScorer> GetTopScorers()
 {
     MyScienceEntities db = new MyScienceEntities();
     //var query = @"SELECT * from db.users ORDER BY Score DESC LIMIT 0,10";
     var query = (from tscorer in db.users
                  orderby tscorer.score descending
                  select new TopScorer
                  {
                      ID = tscorer.ID,
                      Name = tscorer.name,
                      Score = (int)tscorer.score,
                  }
                  );
     return query.ToList<TopScorer>();
 }
Ejemplo n.º 2
0
 public List<Project> GetProjects()
 {
     MyScienceEntities db = new MyScienceEntities();
     var query = (from app in db.projects
                  where app.status == "active"
                  select new Project
                  {
                      ID = app.ID,
                      Name = app.name,
                      Description = app.description,
                      Form = app.form,
                      Owner = app.owner
                  });
     return query.ToList<Project>();
 }
Ejemplo n.º 3
0
        public Uri SubmitData(Submission newsubmission)
        {
            int id = newsubmission.ID;
            int projectid = newsubmission.ProjectID;
            int userid = newsubmission.UserID;
            String data = newsubmission.Data;
            String location = newsubmission.Location;
            byte[] imagedata = newsubmission.ImageData;
            byte[] lowresimagedata = newsubmission.LowResImageData;
            DateTime time = newsubmission.Time;
            String imagename = newsubmission.ImageName;
            //String lowresimagename = newsubmission.LowResImageName;

            EnsureContainerExists();
            EnsureLowResImagesContainerExists();
            //DateTime time = DateTime.Now;
            //String imagename = userid.ToString() + "-" + time.ToFileTime().ToString() + ".jpg";
            var blob = this.GetContainer().GetBlobReference(imagename);
            blob.Properties.ContentType = "JPEG";
            var lowresblob = this.GetLowResImagesContainer().GetBlobReference(imagename);
            lowresblob.Properties.ContentType = "JPEG";

            var metadata = new NameValueCollection();
            metadata["SubmissionID"] = id.ToString();
            metadata["ProjectID"] = projectid.ToString();
            metadata["UserID"] = userid.ToString();
            metadata["Time"] = DateTime.Now.ToString();

            blob.Metadata.Add(metadata);
            blob.UploadByteArray(imagedata);
            lowresblob.Metadata.Add(metadata);
            lowresblob.UploadByteArray(lowresimagedata);

            int point = 1;//for each submission increase user score by 1
            using (var db = new MyScienceEntities())
            {
                datum submission = datum.Createdatum(id, projectid, userid, data, time, location, blob.Uri.ToString(), lowresblob.Uri.ToString());
                db.data.AddObject(submission);
                user curUser = (from auser in db.users
                                where auser.ID == userid
                                select auser).First();
                curUser.score = curUser.score + point;
                int changes = db.SaveChanges();
                //return changes;
            }
            return blob.Uri;
        }
Ejemplo n.º 4
0
 public List<Submission> GetUserSubmission(int userid)
 {
     MyScienceEntities db = new MyScienceEntities();
     var query = (from d in db.data
                  from p in db.projects
                  where d.userid == userid && d.projectid == p.ID
                  select new Submission
                  {
                      ID = d.ID,
                      UserID = userid,
                      ProjectID = p.ID,
                      ProjectName = p.name,
                      Data = d.data,
                      Location = d.location,
                      Time = d.time,
                      ImageName = d.picture,
                      LowResImageName = d.lowrespic
                  });
     List<Submission> result = query.ToList<Submission>();
     //EnsureContainerExists();
     //CloudBlobContainer container = this.GetContainer();
     //for (int i = 0; i < result.Count; i++)
     //{
     //    CloudBlob blob = container.GetBlobReference(result[i].ImageName);
     //    BlobStream blobstream = blob.OpenRead();
     //    MemoryStream ms = new MemoryStream();
     //    blobstream.CopyTo(ms);
     //    result[i].ImageData = ms.ToArray();
     //}
     return result;
 }
Ejemplo n.º 5
0
 public List<Submission> GetProjectData(int projectid)
 {
     MyScienceEntities db = new MyScienceEntities();
     var query = (from sub in db.data
                  where sub.projectid == projectid
                  select new Submission
                  {
                      ID = sub.ID,
                      ProjectID = sub.projectid,
                      UserID = sub.userid,
                      Data = sub.data,
                      Location = sub.location,
                      ImageName = sub.picture,
                      Time = sub.time
                  });
     return query.ToList<Submission>();
 }
Ejemplo n.º 6
0
        public User RegisterUserWithImage(int id, String phoneid, String name, String contentType, byte[] imagedata)
        {
            /* Handle new user creation */
            //check to see if the user is in the database
            MyScienceEntities db = new MyScienceEntities();
            var query = (from userobj in db.users
                         where userobj.name.ToLower() == name.ToLower()// && userobj.phoneid == phoneid
                         select new User
                         {
                             ID = userobj.ID,
                             Name = userobj.name,
                             Score = (int)userobj.score
                         });
            if (query.Count<User>() != 0)
                return null; //username already taken

            int idx = db.users.Count<user>() + 1;
            user userinfo = user.Createuser(idx, phoneid, name);
            userinfo.score = 0;
            //userinfo.hasImage = 1; //has user profile pic
            db.users.AddObject(userinfo);
            int changes = db.SaveChanges();
            User result = new User
            {
                ID = userinfo.ID,
                Name = userinfo.name,
                Score = (int)userinfo.score,
                PhoneID = userinfo.phoneid,
                hasImage = 1
            };

            /* Handle image submission */
            EnsureUserImagesContainerExists();
            String imagename = name + ".jpg";
            var blob = this.GetUserImagesContainer().GetBlobReference(imagename);
            blob.Properties.ContentType = contentType;

            var metadata = new NameValueCollection();
            //metadata["PhoneID"] = phoneid.ToString();
            //metadata["UserID"] = idx.ToString();
            metadata["Time"] = DateTime.Now.ToString();

            blob.Metadata.Add(metadata);
            blob.UploadByteArray(imagedata);

            return result;
        }
Ejemplo n.º 7
0
        public User RegisterUser(int id, String phoneid, String name)
        {
            //check to see if the user is in the database
            MyScienceEntities db = new MyScienceEntities();
            var query = (from userobj in db.users
                         where userobj.name.ToLower() == name.ToLower()// && userobj.phoneid == phoneid
                         select new User
                         {
                             ID = userobj.ID,
                             Name = userobj.name,
                             Score = (int)userobj.score
                         });
            if (query.Count<User>() != 0)
                return null; //username already taken

            int idx = db.users.Count<user>() + 1;
            user userinfo = user.Createuser(idx, phoneid, name);
            userinfo.score = 0;
            //userinfo.hasImage = 0; //without user profile pic
            db.users.AddObject(userinfo);
            int changes = db.SaveChanges();
            User result = new User
            {
                ID = userinfo.ID,
                Name = userinfo.name,
                Score = (int)userinfo.score,
                PhoneID = userinfo.phoneid,
                hasImage = 0
            };
            return result;
        }
Ejemplo n.º 8
0
 public List<User> GetUserProfile(String username, String phoneID)
 {
     MyScienceEntities db = new MyScienceEntities();
     var query = (from user in db.users
                  where user.name.ToLower() == username.ToLower()// && user.phoneid == phoneID
                  select new User
                  {
                      ID = user.ID,
                      Name = user.name,
                      Score = (int)user.score
                  });
     return query.ToList<User>();
 }