public override void Reset() { images = new FlowObservableCollection <ImageNews>(); if (Helper.Instance().CheckLogin()) { personalPost = new PersonalPost() { urlAvarta = Helper.Instance().MyAccount.Avatar_Uri, fullName = Helper.Instance().AccountChat.FullName }; } }
public async Task <IActionResult> Create(string Content) { PersonalPost personalPost = new PersonalPost(); personalPost.Content = Content; if (ModelState.IsValid) { personalPost.Id = Guid.NewGuid(); List <IFormFile> images = Request.Form.Files.Where(f => f.Name == "images[]").ToList(); string[] imgNameList = _UploadImages(images, personalPost.Id.ToString()); personalPost.ImageUrls = (imgNameList != null) ? string.Join(";", imgNameList) : null; personalPost.InsertDate = DateTime.Now; personalPost.LastUpdated = DateTime.Now; personalPost.UserId = _userManager.GetUserId(User); _context.Add(personalPost); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(personalPost)); }
public async Task <IActionResult> Edit(Guid id, [Bind("Id,Content,StoredImageUrls,NewImages,InsertDate,LastUpdated,UserId")] PersonalPostViewModel personalPostViewModel) { if (id != personalPostViewModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { PersonalPost personalPost = _context.PersonalPost.Where(p => p.Id == id).FirstOrDefault(); personalPost.Content = personalPostViewModel.Content; personalPost.InsertDate = personalPostViewModel.InsertDate; personalPost.LastUpdated = DateTime.Now; personalPost.UserId = personalPostViewModel.UserId; string existingImages = _context.PersonalPost.Where(p => p.Id == personalPost.Id).FirstOrDefault().ImageUrls; //delete unselected images if (existingImages != null && existingImages != "") { if (personalPostViewModel.StoredImageUrls == null) { _DeleteImages(personalPost.ImageUrls); } else { foreach (string image in personalPost.ImageUrls.Split(";")) { if (!personalPostViewModel.StoredImageUrls.Contains(image)) { _DeleteOneImage(image); } } } } //upload image new images int startNumber = 0; if (personalPost.ImageUrls != null && personalPost.ImageUrls != "") { startNumber = personalPost.ImageUrls.Split(";").Count(); } string[] newImages = _UploadImages(personalPostViewModel.NewImages, personalPost.Id.ToString(), startNumber + 1); personalPost.ImageUrls = _CreateImageUrls(personalPostViewModel.StoredImageUrls, newImages); _context.Update(personalPost); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!_PersonalPostExists(personalPostViewModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(personalPostViewModel)); }