public async Task <IActionResult> ShareLibrary(PostLibrary postLibrary, IEnumerable <IFormFile> MainImage) { PostLibraryDTO model = new PostLibraryDTO(); foreach (var file in MainImage) { if (file.Length > 0) { using (var ms = new System.IO.MemoryStream()) { file.CopyTo(ms); var fileBytes = ms.ToArray(); string s = Convert.ToBase64String(fileBytes); model.ImgLogo.Base64 = s; model.ImgLogo.FileName = file.FileName; model.ImgLogo.ExtensionType = file.ContentType; } } } postLibrary.LastEditDate = DateTime.Now; model.Data = postLibrary; var result = await _repoWrapper.Library.CreateLibrary(model); return(Redirect("/tai-khoan?id=2")); }
public async Task <PostLibraryDTO> PostLibrary(PostLibraryDTO model) { _logger.LogDebug($"PostLibrary: {JsonConvert.SerializeObject(model)}"); var output = new PostLibraryDTO(); try { var LibraryModel = _mapper.Map <Library>(model.Data); var LibraryId = await _repoWrapper.Library.PostLibrary(LibraryModel, model.ImgLogo, model.UserId); if (LibraryId != 0) { // Save MainImage if (!String.IsNullOrEmpty(model.ImgLogo.Base64)) { await SaveLogoImage(model.ImgLogo, LibraryId); } output.Data.Library_ID = LibraryId; ////Update Image //_repoWrapper.Brand.UpdateImgProductBrand(ProductBrandModel, model.ImgLogo, model.ImgBanner, ProdBrandId, model.UserId); await _repoWrapper.FCMMessage.PushNotificationToRabitMQ(new NotificationRabitMQModel { Type = "ONDEMAND", NotificationCode = "DKCH", ChannelSend = "ALL", UsingTemplate = true, UserId = model.UserId, }); output.ErrorCode = "00"; output.Message = "Tạo kiến thức thành công"; } else { output.ErrorCode = "001"; output.Message = Utils.ConstMessage.GetMsgConst("001"); } } catch (Exception ex) { _logger.LogError($"PostLibrary: " + ex.ToString()); output.ErrorCode = "001"; output.Message = Utils.ConstMessage.GetMsgConst("001"); } return(output); }
public async Task <PostLibraryDTO> CreateLibrary(PostLibraryDTO postLibraryDTO) { PostLibraryDTO output = new PostLibraryDTO(); var jwt = JsonConvert.DeserializeObject <SumProfileResponseDTO>(_httpContextAccessor.HttpContext.Request.Cookies["JWT"]); if (jwt != null) { _client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", jwt.JWT); postLibraryDTO.UserId = jwt.UserId; string apiUrl = $"/api/v1/Library/PostLibrary"; var json = JsonConvert.SerializeObject(postLibraryDTO, Formatting.Indented); var stringContent = new StringContent(json, Encoding.UTF8, "application/json"); var response = await _client.PostAsync(apiUrl, stringContent); if (response.IsSuccessStatusCode) { string responseStream = await response.Content.ReadAsStringAsync(); output = JsonConvert.DeserializeObject <PostLibraryDTO>(responseStream); } } return(output); }