示例#1
0
        public async Task <bool> UpdateMovement()
        {
            try
            {
                if (!Request.Content.IsMimeMultipartContent())
                {
                    return(false);
                }
                var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

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

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

                    return(BLL.VOD.UpdateMovementTraining(MovementObject));
                }
                return(false);
            }
            catch (Exception ee)
            {
                new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.UpdateMovement, "", -400, ee.Message); }).Start();
                return(true);
            }
        }
示例#2
0
        public async Task <int> PostMovement()
        {
            try
            {
                new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostMovement, "", 0, "start 1"); }).Start();

                if (!Request.Content.IsMimeMultipartContent())
                {
                    new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostMovement, "", -101, "MimeMultipartContent"); }).Start();
                    return(-101);
                }

                int MTID = 0;
                var filesReadToProvider = await Request.Content.ReadAsMultipartAsync();

                Com.MovementTraining MovementObject = new Com.MovementTraining();
                new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostMovement, "", 0, "start 2"); }).Start();

                foreach (var itemContent in filesReadToProvider.Contents)
                {
                    if (itemContent.Headers.ContentDisposition.Name == "Object")
                    {
                        new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostMovement, "", 0, "start 3"); }).Start();

                        var jsonString = await itemContent.ReadAsStringAsync();

                        var serializer = new JavaScriptSerializer();
                        MovementObject = serializer.Deserialize <Com.MovementTraining>(jsonString);
                        new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostMovement, "", 0, "start 4"); }).Start();

                        int ResAdd = BLL.VOD.AddMovementTraining(MovementObject);
                        if (ResAdd < 0)
                        {
                            new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostMovement, "", -102, "cant Add to DB"); }).Start();
                            return(-102);
                        }
                        else
                        {
                            MTID = ResAdd;
                        }
                    }
                    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/" + MTID);

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

                        NameNewFile = NameNewFile + "/GifImg" + HeaderType;

                        File.WriteAllBytes(NameNewFile, fileBytes);

                        //  new System.Threading.Thread(delegate () { BLL.Log.DoLog(Com.Common.Action.PostMovement, "", -102, "cant Add to DB"); }).Start();

                        return(MTID);
                    }
                    else
                    {
                        new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostMovement, "", -106, "Ye Chize ezafi too req boode"); }).Start();
                        return(-106);
                    }
                }
                return(-104);
            }
            catch (Exception ee)
            {
                new System.Threading.Thread(delegate() { BLL.Log.DoLog(Com.Common.Action.PostMovement, "", -400, ee.Message); }).Start();
                return(-105);
            }
        }