예제 #1
0
 public Boolean upload([FromBody] FileUploadModel file)
 {
     if (!isValidateApiUser(file.token))
     {
         return(false);
     }
     try
     {
         db.Files.Add(file.file);
         IQueryable <UserPlanModel> up = db.UserPlans.Where(u => u.username == file.file.username).OrderBy(u => u.priority);
         int flag = 0;
         foreach (UserPlanModel u in up)
         {
             if (u.storageRemaining >= file.file.size)
             {
                 u.storageRemaining -= file.file.size;
                 db.Entry(u).State   = EntityState.Modified;
                 flag = 1;
                 break;
             }
         }
         if (flag == 0)
         {
             return(false);
         }
         db.SaveChanges();
         return(true);
     }catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
예제 #2
0
        public IHttpActionResult PutTokenUsersModel(string id, TokenUsersModel tokenUsersModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tokenUsersModel.token)
            {
                return(BadRequest());
            }

            db.Entry(tokenUsersModel).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!TokenUsersModelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
예제 #3
0
        public bool UpdatePass(string username, [FromBody] string password)
        {
            TokenUserModel user = db.Tokens.Find(username);

            if (user == null)
            {
                return(false);
            }
            user.password = password;
            db.Entry <TokenUserModel>(user).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return(false);
            }
        }
예제 #4
0
        public String upload([FromBody] FileModel file)
        {
            int flag = 0;

            while (flag == 0)
            {
                file.token = Guid.NewGuid().ToString();
                var files = db.Files.ToList();
                flag = 1;
                foreach (FileModel f in files)
                {
                    if (file.token == f.token)
                    {
                        flag = 0;
                        break;
                    }
                }
            }
            db.Files.Add(file);
            IQueryable <UserPlanModel> up = db.UserPlans.Where(u => u.username == file.username).OrderBy(u => u.priority);

            flag = 0;
            foreach (UserPlanModel u in up)
            {
                if (u.storageRemaining >= file.size)
                {
                    u.storageRemaining -= file.size;
                    db.Entry <UserPlanModel>(u).State = EntityState.Modified;
                    flag = 1;
                    break;
                }
            }
            if (flag == 0)
            {
                return(null);
            }
            db.SaveChanges();
            return(file.token);
        }
예제 #5
0
 public Boolean updateContact([FromBody] ContactUpdateModel user)
 {
     try
     {
         UserModel u;
         if ((u = db.Users.Find(user.username)) == null)
         {
             return(false);
         }
         u.email = user.email;
         db.Entry <UserModel>(u).State = EntityState.Modified;
         db.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
         return(false);
     }
 }
예제 #6
0
        public Boolean addMembers(GroupMemberCreateModel group)
        {
            /*con.ConnectionString = @"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=RSSDB;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
             * int[] userid = new int[users.Length];
             * try
             * {
             *  using (con)
             *  {
             *      string command = "";
             *      SqlCommand cmd = new SqlCommand();
             *      SqlDataReader rdr;
             *      cmd.Connection = con;
             *      SqlParameter gid = new SqlParameter("@gid", id);
             *      command = "Select id from Group where Id=@gid";
             *      cmd.CommandText = command;
             *      cmd.Parameters.Add(gid);
             *      con.Open();
             *      rdr = cmd.ExecuteReader();
             *      if (rdr == null)
             *      {
             *          return false;
             *      }
             *      command = "Select id from User where username=@uname";
             *      cmd.CommandText = command;
             *      for (int i = 0; i < users.Length; i++)
             *      {
             *          SqlParameter uname = new SqlParameter("@uname", users[i]);
             *          cmd.Parameters.Add(uname);
             *          rdr = cmd.ExecuteReader();
             *          if (rdr != null)
             *          {
             *              userid[i] = (int)rdr["id"];
             *              rdr.Close();
             *          }
             *          else
             *          {
             *              return false;
             *          }
             *      }
             *      command = "INSERT INTO Group_Member(Id,userid,reqStatus) VALUES(@gid,@uid,0)";
             *      cmd.CommandText = command;
             *      cmd.Parameters.Add(gid);
             *      SqlParameter uid = new SqlParameter();
             *      uid.ParameterName = "@uid";
             *      for (int i = 0; i < users.Length; i++)
             *      {
             *          uid.Value = userid[i];
             *          cmd.Parameters.Add(uid);
             *          if (cmd.ExecuteNonQuery() <= 0)
             *          {
             *              return false;
             *          }
             *      }
             *      con.Close();
             *      return true;
             *
             *  }
             * }
             * catch (Exception ex)
             * {
             *  Console.Write("Errors: " + ex.Message);
             *  return false;
             * }*/

            //object[] ob = { group.id };
            GroupModel g = db.Groups.Find(group.id);

            if (g == null)
            {
                return(false);
            }
            if (g.owner != group.owner)
            {
                return(false);
            }


            List <GroupMemberModel> gms = new List <GroupMemberModel>();

            foreach (string uname in group.users)
            {
                if (db.Users.Find(uname) != null && db.GroupMembers.Find(group.id, uname) == null)
                {
                    GroupMemberModel gm = new GroupMemberModel();
                    gm.id         = group.id;
                    gm.username   = uname;
                    gm.reqStatus  = false;
                    g.reqPending += 1;
                    gms.Add(gm);
                }
            }
            if (db.GroupMembers.Find(group.id, group.owner) == null)
            {
                gms.Add(new GroupMemberModel()
                {
                    id = group.id, reqStatus = true, username = group.owner
                });
            }
            db.GroupMembers.AddRange(gms);
            db.Entry <GroupModel>(g).State = EntityState.Modified;
            db.SaveChanges();
            return(true);
        }