public async Task <ApiResponse> DeleteHeadInfomation(HeadInformation headInformation) { try { _headInformationDataRepository.Delete(headInformation); await _headInformationDataRepository.SaveChangesAsync(); var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "img", headInformation.ImagePath); if (File.Exists(path)) { File.Delete(path); } return(new ApiResponse() { Status = "success", Message = "Successfully delete Head Infomation" }); } catch (Exception ex) { return(new ApiResponse() { Status = "fail", Message = ex.Message }); } }
public Data(HeadInformation headInfo, Message msg) { HeadInfo = headInfo; DataSize = GetBytes(JsonConvert.SerializeObject(msg)).Length; Data_Str = ((int)headInfo).ToString() + DataSize.ToString() + JsonConvert.SerializeObject(msg); Data_Byte = GetBytes(Data_Str).Length == 1024 ? GetBytes(Data_Str + " ") : GetBytes(Data_Str); Data_Message = msg; }
public Data(HeadInformation headInfo) { HeadInfo = headInfo; DataSize = 0; Data_Str = ((int)headInfo).ToString() + DataSize.ToString(); Data_Byte = GetBytes(Data_Str).Length == 1024 ? GetBytes(Data_Str + " ") : GetBytes(Data_Str); Data_Message = null; }
public async Task <IActionResult> SaveImage() { try { var httpRequest = HttpContext.Request; if (httpRequest.Form.Files.Count > 0) { var uploadFile = httpRequest.Form.Files[0]; // get the uploaded file if (uploadFile != null && uploadFile.Length > 0) { var path = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot", "img", uploadFile.FileName); if (!System.IO.File.Exists(path)) { using (var stream = new FileStream(path, FileMode.Create)) { uploadFile.CopyTo(stream); stream.Close(); } } if (_headInformationDataRepository.Queryable.Where(img => img.ImagePath == path).Count() == 0) { HeadInformation imageModel = new HeadInformation(); imageModel.Content = ""; imageModel.ImagePath = uploadFile.FileName; _headInformationDataRepository.Create(imageModel); await _headInformationDataRepository.SaveChangesAsync(); } return(Ok(new ApiResponse { Status = "success", Message = "Image file uploaded." })); } } return(Ok(new ApiResponse { Status = "fail", Message = "Upload file is empty" })); } catch (Exception ex) { return(Ok(new ApiResponse { Status = "fail", Message = ex.Message })); } }
public async Task <ApiResponse> UpdateHeadInfomation(HeadInformation headInformation) { try { _headInformationDataRepository.Update(headInformation); await _headInformationDataRepository.SaveChangesAsync(); return(new ApiResponse() { Status = "success", Message = "Successfully update Head Infomation" }); } catch (Exception ex) { return(new ApiResponse() { Status = "fail", Message = ex.Message }); } }
public async Task <IActionResult> DeleteHeadInfomation([FromBody] HeadInformation headInformation) { var result = await headerInfomationRepository.DeleteHeadInfomation(headInformation); return(Ok(result)); }