Пример #1
0
 public bool DeleteImg(int MTID, int MTDID)
 {
     try
     {
         Com.MovementTrainingDetail movementTrainingDetail = new Com.MovementTrainingDetail()
         {
             MTDID = MTDID, MTID = MTID, ImgName = ""
         };
         var ResMovement = BLL.VOD.UpdateMovementTrainingImgAddress(movementTrainingDetail);
         if (!ResMovement)
         {
             return(false);
         }
         else
         {
             string   rootFolder = @"C:\inetpub\wwwroot\FitnessResource\Movement\" + MTID.ToString() + @"\" + MTDID.ToString();
             string[] files      = Directory.GetFiles(rootFolder);
             foreach (var file in files)
             {
                 File.Delete(file);
             }
             return(true);
         }
     }
     catch (Exception e)
     {
         BLL.Log.DoLog(Com.Common.Action.DeleteImg, " ", -100, e.Message);
         return(false);
     }
 }
Пример #2
0
        public async Task <bool> PostUpdateMovementTrainingContext()
        {
            try
            {
                if (!Request.Content.IsMimeMultipartContent())
                {
                    return(false);
                }
                var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

                Com.MovementTrainingDetail movementTrainingDetail = new Com.MovementTrainingDetail();

                if (filesReadToProvider.Contents[0].Headers.ContentDisposition.Name == "Object")
                {
                    var jsonString = await filesReadToProvider.Contents[0].ReadAsStringAsync();
                    var serializer = new JavaScriptSerializer();
                    movementTrainingDetail = serializer.Deserialize <Com.MovementTrainingDetail>(jsonString);

                    return(BLL.VOD.UpdateMovementTrainingContext(movementTrainingDetail));
                }
                return(false);
            }
            catch (Exception ee)
            {
                new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostUpdateMovementTrainingContext, "", -400, ee.Message); }).Start();
                return(false);
            }
        }
Пример #3
0
        public async Task <IHttpActionResult> PostUpdateImgMovementDetail()
        {
            try
            {
                if (!Request.Content.IsMimeMultipartContent())
                {
                    return(StatusCode(HttpStatusCode.UnsupportedMediaType));
                }

                var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

                Com.MovementTrainingDetail MovementObject = new Com.MovementTrainingDetail();

                int    MainMTDID  = 0;
                int    MainMTID   = 0;
                int    ImgCount   = 0;
                string ImgAddress = "";

                foreach (var itemContent in filesReadToProvider.Contents)
                {
                    if (itemContent.Headers.ContentDisposition.Name == "Object")
                    {
                        var jsonString = await itemContent.ReadAsStringAsync();

                        var serializer = new JavaScriptSerializer();
                        MovementObject = serializer.Deserialize <Com.MovementTrainingDetail>(jsonString);

                        var ResAdd = BLL.VOD.GetMovementTrainingDetailByID(MovementObject.MTDID);
                        if (ResAdd == null)
                        {
                            return(BadRequest());
                        }
                        MainMTDID = MovementObject.MTDID;
                        MainMTID  = MovementObject.MTID;
                    }
                    else if (itemContent.Headers.ContentDisposition.Name == "File")
                    {
                        var fileBytes = await itemContent.ReadAsByteArrayAsync();

                        string HeaderType = itemContent.Headers.ContentDisposition.FileName;

                        string NameNewFile = System.Web.Hosting.HostingEnvironment.MapPath("~/FitnessResource/Movement/" + MainMTID + "/" + MainMTDID);

                        if (!Directory.Exists(NameNewFile))
                        {
                            Directory.CreateDirectory(NameNewFile);
                        }

                        NameNewFile = NameNewFile + "/" + ImgCount + HeaderType;

                        File.WriteAllBytes(NameNewFile, fileBytes);

                        if (ImgCount > 0)
                        {
                            ImgAddress = ImgAddress + ",";
                        }

                        ImgAddress = ImgAddress + ImgCount + HeaderType;
                        ImgCount++;
                    }
                    else
                    {
                        return(BadRequest());
                    }
                }

                MovementObject.ImgName = ImgAddress;
                BLL.VOD.UpdateMovementTrainingImgAddress(MovementObject);

                return(Ok());
            }
            catch (Exception ee)
            {
                new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostMovementDetail, "", -400, ee.Message); }).Start();
                return(BadRequest());
            }
        }