public void Execute(AddPicture request)
        {
            _validator.ValidateAndThrow(request);

            var picDto = Context.Pictures.Find(request);

            if (picDto != null)
            {
                try
                {
                    picDto.alt         = request.Alt;
                    picDto.src         = request.Src;
                    picDto.IsDeleted   = false;
                    picDto.ModifidedAt = DateTime.Now;
                    Context.SaveChanges();
                }
                catch (Exception)
                {
                    throw new Exception();
                }
            }
            else
            {
                throw new EntityNotFoundException(picDto.Id, typeof(AddPicture));
            }
        }
Example #2
0
 void Start()
 {
     AddData = GameObject.Find("Manager").GetComponent <AddPicture>();
     //輸出路徑
     print(System.IO.Path.Combine(Application.persistentDataPath, "test"));
     //心智測驗json
     if (File.Exists(System.IO.Path.Combine(Application.persistentDataPath, "test")))
     {
         print("file exist");
     }
     else
     {
         print("file not exist");
         playerState_test myPlayer1  = new playerState_test();
         string           saveString = JsonUtility.ToJson(myPlayer1);
         StreamWriter     file       = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, "test"));
         file.Write(saveString);
         file.Close();
     }
     //拼圖json
     if (File.Exists(System.IO.Path.Combine(Application.persistentDataPath, "puzzle")))
     {
         print("file exist");
     }
     else
     {
         print("file not exist");
         playerState_puzzle myPlayer1  = new playerState_puzzle();
         string             saveString = JsonUtility.ToJson(myPlayer1);
         StreamWriter       file       = new StreamWriter(System.IO.Path.Combine(Application.persistentDataPath, "puzzle"));
         file.Write(saveString);
         file.Close();
     }
 }
Example #3
0
        private async void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            var add = new AddPicture(AdminInterface);

            add.ShowDialog();
            if (add.Picture != null)
            {
                await Task.Run(() => RefreshList());
            }
        }
Example #4
0
 public IActionResult Post([FromBody] AddPicture dto, [FromServices] ICreatePictureCommand com)
 {
     try
     {
         executor.ExecuteCommand(com, dto);
         return(StatusCode(202, "Picture added"));
     }
     catch (EntityAllreadyExists)
     {
         return(StatusCode(422, "Fail"));
     }
 }
Example #5
0
 public IActionResult Put(int id, [FromBody] AddPicture dto, [FromServices] ICreatePictureCommand com)
 {
     try
     {
         dto.Id = id;
         executor.ExecuteCommand(com, dto);
         return(StatusCode(201, "Picture edited"));
     }
     catch
     {
         return(StatusCode(422, "Fail"));
     }
 }
Example #6
0
 public void GetPicModelAsync(string pageUrl)
 {
     Task.Factory.StartNew(() =>
     {
         var url             = pageUrl;
         var client          = new WebClient();
         var pageSize        = this.GetPageCount(GetPageString(pageUrl));
         List <PicModel> pms = new List <PicModel>();
         Regex reg           = new Regex(@"<div class=""gdtm"".*?<a href=""(.*?)"".*?</div>");
         var ChildReg        = new Regex(@"<div id=""i3"">.*?<img id=""img"" src=""(.*?)"".*?</div>");
         int index           = 0;
         //先读取所有的链接之后再进行下载,可以得到进度
         List <string> links = new List <string>();
         for (var i = 0; i < pageSize; i++)
         {
             var masterPageHtml = client.DownloadString(string.Format(url, i));
             if (reg.IsMatch(masterPageHtml))
             {
                 foreach (Match m in reg.Matches(masterPageHtml))
                 {
                     //解析LINK链接 从新的html中找到Image的地址并且下载图片
                     var downloadClient = new WebClient();
                     var ChildPageHtml  = downloadClient.DownloadString(m.Groups[1].Value);
                     if (ChildReg.IsMatch(ChildPageHtml))
                     {
                         Match mm    = ChildReg.Match(ChildPageHtml);
                         var imgLink = mm.Groups[1].Value;
                         var pm      = new PicModel()
                         {
                             ImgUrl = imgLink, Index = index++
                         };
                         AddPicture?.Invoke(pm);
                     }
                 }
             }
         }
     });
 }
Example #7
0
        public void Execute(AddPicture request)
        {
            var pic = new Domain.Picture
            {
                src    = request.Src,
                alt    = request.Alt,
                PostId = request.PostId
            };

            if (Context.Pictures.Any(t => t.src == request.Src))
            {
                throw new EntityAllreadyExists("Picture " + pic.Id);
            }
            Context.Pictures.Add(pic);
            try
            {
                Context.SaveChanges();
            }
            catch (Exception)
            {
                throw new Exception();
            }
        }