예제 #1
0
        public HttpResponseMessage Put(Guid id, [FromBody] BlogDTO blogDTO)
        {
            var blog = BlogApplication.Get(id);

            if (blog == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new Note("Blog não encontrado", Note.NoteType.Error)));
            }

            var converter = new BlogConverter();

            converter.Convert(blogDTO, blog);
            try
            {
                BlogApplication.Save(blog);
                return(Request.CreateResponse(HttpStatusCode.OK, new Note("Blog salvo com sucesso", Note.NoteType.Success)));
            }
            catch (InvalidModelState ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new Note("Não foi possível salvar o blog", ex.Details, Note.NoteType.Warning)));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new Note("Não foi possível salvar o blog", ex.Message, Note.NoteType.Error)));
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Пример шаблона проектирования \"Мост\"");

            var blogApplication  = new BlogApplication(new DarkTheme());
            var storeApplication = new StoreApplication(new LightTheme());
            var webSite          = new WebSite(new LightTheme(), new DarkTheme());

            blogApplication.Init();
            Console.WriteLine();

            storeApplication.Init();
            Console.WriteLine();

            Console.WriteLine("Модифицируем реализацию ");
            storeApplication.Themes = new Theme[1] {
                new DarkTheme()
            };
            storeApplication.Init();
            Console.WriteLine();

            webSite.Init();
            Console.WriteLine();

            Console.ReadKey();
        }
예제 #3
0
        internal Blog(BlogApplication blogApplication)
        {
            BlogApplicationId = blogApplication.Id;
            BlogApplication   = blogApplication ?? throw new ArgumentNullException(nameof(blogApplication));
            BlogApplication.blogs.Load(this, _ => { return(new long().NewId()); });

            posts  = new ConcurrentDictionary <long, Post>();
            _posts = new ReadOnlyDictionary <long, Post>(posts);
        }
 private void bindControls()
 {
     BlogApplication.InitImageLoader(this);
     imgLoader           = ImageLoader.Instance;
     displayImageOptions = new DisplayImageOptions.Builder()
                           .ShowImageForEmptyUri(Resource.Drawable.girl)
                           .ShowImageOnFail(Resource.Drawable.girl)
                           .ShowImageOnLoading(Resource.Drawable.girl)
                           .CacheInMemory(true)
                           .CacheOnDisk(true)
                           .ResetViewBeforeLoading()
                           .Build();
     btnBack        = FindViewById <Button>(Resource.Id.title_bar_back);
     btnBack.Click += delegate { Finish(); };
     textName       = FindViewById <TextView>(Resource.Id.text_nickname);
     textAge        = FindViewById <TextView>(Resource.Id.text_age);
     myBlog         = FindViewById <LinearLayout>(Resource.Id.my_blog);
     myBlog.Click  += delegate
     {
         if (CommonHelper.userInfo == null)
         {
             Msg.AppMsg.MakeText(this, "请先登录", Msg.AppMsg.STYLE_INFO).Show();
             return;
         }
         StartActivity(new Intent(this, typeof(MyPostsActivity)));
     };
     myCollect        = FindViewById <LinearLayout>(Resource.Id.my_collect);
     myCollect.Click += delegate
     {
         if (CommonHelper.userInfo == null)
         {
             Msg.AppMsg.MakeText(this, "请先登录", Msg.AppMsg.STYLE_INFO).Show();
             return;
         }
         StartActivity(new Intent(this, typeof(BookMarksActivity)));
     };
     setting        = FindViewById <LinearLayout>(Resource.Id.setting);
     setting.Click += delegate
     {
         AlertDialog.Builder builder = new AlertDialog.Builder(this);
         builder.SetMessage("APP作者:胡帅。一个不出名的帅小伙,只想安安静静写个代码。");
         builder.SetPositiveButton("我知道啦", (object sender, DialogClickEventArgs e) =>
         {
             AlertDialog dialog = sender as AlertDialog;
             dialog.Dismiss();
         });
         builder.SetTitle("提示");
         builder.Show();
     };
     btnLoginOut        = FindViewById <Button>(Resource.Id.btn_loginout);
     btnLoginOut.Click += btnLoginOut_Click;
     rImgView           = FindViewById <RoundImageView>(Resource.Id.img_headPic);
 }
예제 #5
0
        public BlogDTO Get()
        {
            var blog = BlogApplication.Get().FirstOrDefault();

            if (blog == null)
            {
                throw new HttpResponseException(HttpStatusCode.NotFound);
            }

            var dto = new BlogDTO(blog);

            return(dto);
        }
예제 #6
0
 protected void InitalComponents()
 {
     BlogApplication.InitImageLoader(this.Context);
     imgLoader           = ImageLoader.Instance;
     displayImageOptions = new DisplayImageOptions.Builder()
                           .ShowImageForEmptyUri(Resource.Drawable.girl)
                           .ShowImageOnFail(Resource.Drawable.girl)
                           .ShowImageOnLoading(Resource.Drawable.girl)
                           .CacheInMemory(true)
                           .CacheOnDisk(true)
                           .ResetViewBeforeLoading()
                           .Build();
 }
예제 #7
0
 protected void InitalComponents()
 {
     BlogApplication.InitImageLoader(this);
     imgLoader           = ImageLoader.Instance;
     displayImageOptions = new DisplayImageOptions.Builder()
                           .ShowImageForEmptyUri(Resource.Drawable.girl)
                           .ShowImageOnFail(Resource.Drawable.girl)
                           .ShowImageOnLoading(Resource.Drawable.girl)
                           .CacheInMemory(true)
                           .CacheOnDisk(true)
                           .ResetViewBeforeLoading()
                           .Build();
     btnBack        = FindViewById <Button>(Resource.Id.title_bar_back);
     btnBack.Click += delegate { Finish(); };
     textPageTitle  = FindViewById <TextView>(Resource.Id.head_title);
     ptrl           = FindViewById <PullToRefreshLayout>(Resource.Id.refresh_view);
     pListView      = FindViewById <PullableListView>(Resource.Id.pListView);
 }
예제 #8
0
        public HttpResponseMessage Delete(Guid id)
        {
            var blog = BlogApplication.Get(id);

            if (blog == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound, new Note("Blog não encontrado", Note.NoteType.Error)));
            }

            try
            {
                BlogApplication.Delete(blog);
                return(Request.CreateResponse(HttpStatusCode.OK, new Note("Blog excluído com sucesso", Note.NoteType.Success)));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new Note("Não foi possível excluir o blog", ex.Message, Note.NoteType.Error)));
            }
        }
예제 #9
0
        public HttpResponseMessage Post(BlogDTO blogDTO)
        {
            var blog      = new Blog();
            var converter = new BlogConverter();

            converter.Convert(blogDTO, blog);

            try
            {
                BlogApplication.Save(blog);
                return(Request.CreateResponse(HttpStatusCode.OK, new Note("Blog adicionar com sucesso", Note.NoteType.Success)));
            }
            catch (InvalidModelState ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new Note("Não foi possível adicionar o blog", ex.Details, Note.NoteType.Warning)));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new Note("Não foi possível adicionar o blog", ex.Message, Note.NoteType.Error)));
            }
        }