public PostItemListPage() { InitializeComponent(); this.BindingContext = viewModel = new PostItemListPageViewModel(); postItemService = DependencyService.Get <IPostItemService>(); Init(); }
public async void Option_Clicked(object sender, EventArgs e) { int DELETE_POST = 1; int VIEW_PROFILE = 2; int CHAT = 3; var postItem = viewModel.PostItem; IDictionary <int, string> keyValues = new Dictionary <int, string>(); keyValues[VIEW_PROFILE] = Language.thong_tin_ca_nhan; if (UserLogged.IsLogged && postItem.CreatedBy.UserId == UserLogged.Id) { keyValues[DELETE_POST] = Language.xoa_bai_dang; } else { keyValues[CHAT] = "Chat"; } var result = await DisplayActionSheet(Language.tuy_chon, Language.huy, null, keyValues.Values.ToArray()); if (keyValues.ContainsKey(DELETE_POST) && result == keyValues[DELETE_POST]) { var answer = await DisplayAlert(Language.xac_nhan_xoa, Language.ban_co_chac_chan_muon_xoa_tin_dang_nay_khong, Language.xoa, Language.huy); if (!answer) { return; } IPostItemService postItemService = DependencyService.Get <IPostItemService>(); await postItemService.RemovePostItem(postItem.Id); await Navigation.PopAsync(); MessagingCenter.Send <PostItemDetailPage, string>(this, "OnDeleteSuccess", postItem.Id); } else if (result == keyValues[VIEW_PROFILE]) { await Navigation.PushAsync(new UserProfilePage(Guid.Parse(postItem.CreatedBy.UserId))); } else if (keyValues.ContainsKey(CHAT) && result == keyValues[CHAT]) { if (!UserLogged.IsLogged) { await DisplayAlert("", Language.vui_long_dang_nhap, Language.dong); ((AppShell)Shell.Current).SetLoginPageActive(); return; } await Navigation.PushAsync(new ChatPage(postItem.CreatedBy.UserId)); } }
public PostItemDomainServiceTests() { this.postItemRepository = new Mock <IPostItemRepository>(); this.commentRepository = new Mock <ICommentRepository>(); this.userRepository = new Mock <IUserRepository>(); this.userRepository .Setup(x => x.FindById(1)) .Returns(new Core.Domain.User { Email = "*****@*****.**", Id = 1, UserName = "******" }); this.postItemService = new PostItemService( postItemRepository.Object, commentRepository.Object, new Core.Service.Validators.PostValidator(this.userRepository.Object), new Core.Service.Validators.CommentValidator(this.postItemRepository.Object)); }
public PostItemController(IPostItemService postService) { PostService = postService; }
public PostItemController(IPostItemService postItemService) { this.postItemService = postItemService; }
private async void Save_Clicked(object sender, EventArgs e) { // truong hop dang them tu bên post . if (CheckLastPost) { if (postItemService == null) { postItemService = DependencyService.Get <IPostItemService>(); } DateTime?lastTime = postItemService.GatLastPostTime(UserLogged.Id); if (lastTime.HasValue) { var now = DateTime.Now; TimeSpan timeSpan = now.Subtract(lastTime.Value); if (timeSpan.TotalMinutes >= 120) { } else { //Mỗi bài đăng từ tin đăng phải cách 2 tiếng! Vui lòng thử lại. await DisplayAlert("", Language.moi_bai_dang_phai_tu_it_nhat_x_tieng, Language.dong); return; } } } if (string.IsNullOrWhiteSpace(EntryTitle.Text)) { await DisplayAlert("", Language.vui_long_nhap_tieu_de, Language.dong); return; } if (string.IsNullOrWhiteSpace(editor.Text)) { await DisplayAlert("", Language.vui_long_nhap_noi_dung, Language.dong); return; } loadingPopup.IsVisible = true; // kiem tra co hinh thi upload. if (viewModel.Media.Count > 0) { if (viewModel.Media.Count > 9) { loadingPopup.IsVisible = false; await DisplayAlert("", Language.vui_long_chon_toi_da_9_anh, Language.dong); return; } List <MediaFile> listUploadMedia = viewModel.Media.Where(x => x.Path != null).ToList(); if (listUploadMedia.Any()) { MultipartFormDataContent form = new MultipartFormDataContent(); for (int i = 0; i < listUploadMedia.Count; i++) { string imageName = $"postitem_{Guid.NewGuid().ToString()}.jpg"; ImageList.Add(imageName); var media = listUploadMedia[i]; var stream = new MemoryStream(File.ReadAllBytes(media.Path)); var content = new StreamContent(stream); content.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data") { Name = "files" + i, FileName = imageName }; form.Add(content); } var uploadResonse = await UploadImage(form); if (!uploadResonse.IsSuccess) { loadingPopup.IsVisible = false; await DisplayAlert("", uploadResonse.Message, Language.dong); return; } } } PostItem item = new PostItem(); item.Title = EntryTitle.Text.Trim(); item.Type = ControlSegment.GetCurrentIndex(); item.Description = editor.Text; item.Images = ImageList.Any() ? ImageList.ToArray() : null; item.CreatedById = UserLogged.Id; item.CreatedBy = new PostItemUser() { UserId = UserLogged.Id, FullName = UserLogged.FullName, Avatar = UserLogged.AvatarUrl.Replace(ApiConfig.IP2, "") }; item.CreatedDate = DateTime.Now; item.HasImage = ImageList != null && ImageList.Count() > 0; // gia if (EntryPrice.Text.HasValue) { item.HasPrice = true; item.Price = DecimalHelper.ToCurrency(EntryPrice.Text.Value) + " " + (pickerUnitPrice.SelectedItem != null ? ((PriceOption)pickerUnitPrice.SelectedItem).Name.ToLower() : ""); } // dien tich if (!string.IsNullOrWhiteSpace(EntryArea.Text)) { item.HasArea = true; item.Area = EntryArea.Text + "m2"; } if (!string.IsNullOrWhiteSpace(viewModel.Address)) { item.HasAddress = true; item.Address = viewModel.Address; } if (viewModel.Province != null) { item.ProvinceId = viewModel.Province.Id; if (viewModel.District != null) { item.DistrictId = viewModel.District.Id; if (viewModel.Ward != null) { item.WardId = viewModel.Ward.Id; } } } if (LookUpType.SelectedItem != null) { var loaiBatDongSan = LookUpType.SelectedItem as LoaiBatDongSanModel; item.HasLoaiBatDongSan = true; item.BDSTypeId = loaiBatDongSan.Id; } if (CheckSelected(StacklayoutSoPhongtam)) { item.HasSoPhongTam = true; RadBorder radBorder = GetRadBorder(StacklayoutSoPhongtam); var label = radBorder.Content as Label; item.SoPhongTam = int.Parse(label.Text); } if (CheckSelected(StacklayoutSophongngu)) { item.HasSoPhongNgu = true; RadBorder radBorder = GetRadBorder(StacklayoutSophongngu); var label = radBorder.Content as Label; item.SoPhongNgu = int.Parse(label.Text); } if (postItemService == null) { postItemService = DependencyService.Get <IPostItemService>(); } postItemService.AddPostItem(item); MessagingCenter.Send <AddPostItemPage, PostItem>(this, "AddPostItemSuccess", item); loadingPopup.IsVisible = false; await Navigation.PopAsync(); ToastMessageHelper.ShortMessage(Language.luu_thanh_cong); }
public PostController(IPostItemService postItemService, UserManager <ApplicationUser> userManager) { _postItemService = postItemService; _userManager = userManager; }