Пример #1
0
        /// <summary>
        /// 上传头像
        /// </summary>
        public async Task <string> Post()
        {
            string       imageName;
            MysqlConnent myConnent = new MysqlConnent();

            if (!Request.Content.IsMimeMultipartContent())
            {
                throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
            }
            Dictionary <string, string> dic = new Dictionary <string, string>();
            string root = HttpContext.Current.Server.MapPath("~/Image");//指定要将文件存入的服务器物理位置

            Debug.WriteLine(root);
            if (!Directory.Exists(root))
            {
                Directory.CreateDirectory(root);
            }
            var provider = new MultipartFormDataStreamProvider(root);

            try
            {
                // Read the form data.
                await Request.Content.ReadAsMultipartAsync(provider);

                List <string> fileName = new List <string>();

                // This illustrates how to get the file names.
                foreach (MultipartFileData file in provider.FileData)
                {                                                               //接收文件
                    Trace.WriteLine(file.Headers.ContentDisposition.FileName);  //获取上传文件实际的文件名
                    Trace.WriteLine("Server file path: " + file.LocalFileName); //获取上传文件在服务上默认的文件名
                    await Task.Delay(1000);

                    Save(file.LocalFileName, 77, 77);
                    fileName.Add(file.LocalFileName);
                }//TODO:这样做直接就将文件存到了指定目录下,暂时不知道如何实现只接收文件数据流但并不保存至服务器的目录下,由开发自行指定如何存储,比如通过服务存到图片服务器
                foreach (var key in provider.FormData.AllKeys)
                {//接收FormData
                    dic.Add(key, provider.FormData[key]);
                }
                imageName = fileName[0].Substring(fileName[0].Length - 45, 45);
                Debug.WriteLine(imageName);
                string account = dic["Account"];
                myConnent.MySqlWrite("INSERT INTO 图片表() VALUES('" + imageName + "','" + account + "','" + DateTime.Now.ToString("yyyyMMddHHmmss") + "','" + "0" + "','" + "0" + "','" + "暂无" + "','" + "0" + "','" + "暂无" + "','" + "0" + "','" + "0" + "','" + "0" + "','" + DateTime.Now.ToString("yyyyMMddHHmmss") + "')");
                // myConnent.MySqlHasRows("SELECT * FROM 路径表() ")
                myConnent.MySqlWrite("UPDATE 账号表 SET HeadImageName = '" + imageName + "' WHERE Account = '" + account + "'");
            }
            catch
            {
                throw;
            }

            return(imageName);
        }
Пример #2
0
 // POST: api/UserMessage
 /// <summary>
 /// 更改个人信息
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public string PostPeopleMessage([FromBody] User value)
 {
     try
     {
         myConnent.MySqlWrite("UPDATE 账号表 SET userName = '******', sex = '" + value.sex + "', introduction = '" + value.introduction + "', email = '" + value.email + "' WHERE account = '" + value.account + "'");
         return("true");
     }
     catch (Exception e)
     {
         return("false");
     }
 }
Пример #3
0
 // POST: api/Account
 /// <summary>
 /// 注册帐号
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public string PostAccount([FromBody] Sign value)
 {
     try
     {
         MyConnent.MySqlWrite("INSERT INTO 账号表() VALUES('" + value.account + "','" + value.password + "')");
         return(value.account + "," + value.password);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         return(e.ToString());
     }
 }
 // POST: api/Image_Delete
 /// <summary>
 /// 对图片进行假删除
 /// </summary>
 /// <param name="value"></param>
 public string Post([FromBody] DeleteImageModel value)
 {
     try
     {
         myConnent.MySqlWrite("UPDATE 图片表 SET IsDelete = '" + 1 + "' WHERE ImageName = '" + value.imageName + "'");
         return("true");
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.ToString());
         return("error");
     }
 }
Пример #5
0
 // POST: api/Sign
 /// <summary>
 /// 注册帐号
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public string Post([FromBody] Sign value)
 {
     try
     {
         myConnent.MySqlWrite("INSERT INTO 账号表() VALUES('" + value.account + "','" + value.password + "','" + value.username + "','" + "暂无" + "','" + "这个人很懒,什么都没留下" + "','" + "1" + "','" + "head" + "')");
         return("true");
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         return("false");
     }
 }
Пример #6
0
 // POST: api/Follower
 /// <summary>
 /// 关注
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public string Post([FromBody] Follower value)
 {
     try
     {
         MyConnent.MySqlWrite("INSERT INTO 关注表() VALUES('" + value.FollowerAccount + "','" + value.WasFollowederAccount + "')");
         return("true");
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.ToString());
         return("false");
     }
 }
 // POST: api/Follower_Delete
 /// <summary>
 /// 取消关注
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public string Post([FromBody] Follower value)
 {
     try
     {
         MyConnent.MySqlWrite("DELETE FROM 关注表 WHERE FollowerAccount ='" + value.FollowerAccount + "' AND WasFollowederAccount = '" + value.WasFollowederAccount + "'");
         return("true");
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.ToString());
         return("false");
     }
 }
 // POST: api/ImageMessage
 /// <summary>
 /// 添加图片信息
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public string Post([FromBody] ImageModel value)
 {
     try
     {
         myConnent.MySqlWrite("UPDATE 图片表 SET DateTime = '" + value.dateTime + "', Longitude = '" + value.longitude + "', Introduce = '" + value.introduction + "', Latitude = '" + value.latitude + "', RoadID = '" + value.roadID + "', isPublic = '" + value.isPublic + "' WHERE ImageName = '" + value.imageName + "'");
         return("true");
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.ToString());
         return("error");
     }
 }
Пример #9
0
 // POST: api/Comment
 /// <summary>
 /// 添加评论
 /// </summary>
 /// <param name="value"></param>
 public string Post([FromBody] CommentModel value)
 {
     try
     {
         string NewID = myConnent.NewID();
         myConnent.MySqlWrite("INSERT INTO 评论表() VALUES('" + NewID + "','" + value.account + "','" + value.comment + "','" + DateTime.Now.ToString("yyyyMMddHHmmss") + "','" + value.imageName + "','" + "0" + "')");
         Debug.WriteLine(value.comment);
         return("true");
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.ToString());
         return("false");
     }
 }
 // GET: api/ClickLike/5
 /// <summary>
 /// 取消点赞
 /// </summary>
 /// <param name="imageName"></param>
 /// <returns></returns>
 public string Get(string imageName)
 {
     try
     {
         string ClickLikeCount = MyConnent.MySqlReadReturn("SELECT * FROM 图片表 WHERE ImageName ='" + imageName + "'", "ClickLikeCount");
         int    NewCount       = int.Parse(ClickLikeCount);
         NewCount--;
         MyConnent.MySqlWrite("UPDATE 图片表 SET ClickLikeCount ='" + NewCount + "' WHERE ImageName ='" + imageName + "'");
         return("true");
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.ToString());
         return("false");
     }
 }
Пример #11
0
 // POST: api/Road
 /// <summary>
 /// 新增行程
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public string Post([FromBody] Road value)
 {
     try
     {
         string tmpID = myConnent.NewID();
         if (value.introduction == null)
         {
             value.introduction = "无";
         }
         myConnent.MySqlWrite("INSERT INTO 路径表() VALUES('" + tmpID + "','" + value.roadName + "','" + value.account + "','" + value.introduction + "','" + DateTime.Now.ToString("yyyyMMddHHmmss") + "','" + DateTime.Now.ToString("yyyyMMddHHmmss") + "')");
         return(tmpID);
     }
     catch (Exception e)
     {
         return("error");
     }
 }
Пример #12
0
 // POST: api/Password
 /// <summary>
 /// 修改密码
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public string PostChangePassword([FromBody] ChangePassword value)
 {
     try
     {
         string isTrue = myConnent.MySqlHasRows("SELECT * FROM 账号表 WHERE Account = '" + value.account + "' AND Password ='******'");
         if (isTrue == "true")
         {
             myConnent.MySqlWrite("UPDATE 账号表 SET Password = '******' WHERE Account = '" + value.account + "'");
             return("true");
         }
         else
         {
             return("false");
         }
     }
     catch (Exception e)
     {
         return("wrong");
     }
 }
 /// <summary>
 /// 忘记密码
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public string PostForgetPassword([FromBody] ForgetPassword value)
 {
     try
     {
         string isTrue = myConnent.MySqlHasRows("SELECT * FROM 账号表 WHERE Account = '" + value.account + "'");
         if (isTrue == "true")
         {
             Debug.WriteLine(value.newPassword);
             myConnent.MySqlWrite("UPDATE 账号表 SET Password = '******' WHERE Account = '" + value.account + "'");
             return("true");
         }
         else
         {
             return("false");
         }
     }
     catch (Exception e)
     {
         Debug.WriteLine(e.ToString());
         return("error");
     }
 }