public IActionResult DeleteImage(long userId, long imgid) { try { Domain.Socioboard.Models.AssestLibrary Imglibrary = new AssestLibrary(); DatabaseRepository dbr = new DatabaseRepository(_logger, _env); AssestLibrary lstImages = dbr.Single <AssestLibrary>(t => t.UserId == userId && t.Id == imgid); dbr.Delete <Domain.Socioboard.Models.AssestLibrary>(lstImages); return(Ok("Deleted")); } catch (Exception ex) { return(BadRequest("Something went wrong please try after sometime")); } // return Ok(); }
public IActionResult SaveImage(long userId, string imgName, IFormFile files) { var filename = ""; var apiimgPath = ""; var uploads = string.Empty; string imgPath = string.Empty; string imagePath = string.Empty; if (files != null) { if (files.Length > 0) { var fileName = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue.Parse(files.ContentDisposition).FileName.Trim('"'); // await file.s(Path.Combine(uploads, fileName)); filename = Microsoft.Net.Http.Headers.ContentDispositionHeaderValue .Parse(files.ContentDisposition) .FileName .Trim('"'); var tempName = Domain.Socioboard.Helpers.SBHelper.RandomString(10) + '.' + fileName.Split('.')[1]; //apiimgPath = _appSettings.ApiDomain + "/api/Media/get?id=" + $@"{tempName}"; filename = _env.WebRootPath + "\\upload\\UserImages" + $@"\{tempName}"; imgPath = filename; uploads = _appSettings.ApiDomain + "/api/Media/getUserImages?id=" + $@"{tempName}"; // size += file.Length; try { using (FileStream fs = System.IO.File.Create(filename)) { files.CopyTo(fs); fs.Flush(); } filename = uploads; long length = new System.IO.FileInfo(fileName).Length; } catch (System.Exception ex) { if (!string.IsNullOrEmpty(imagePath)) { uploads = imagePath; } } } } else { } Domain.Socioboard.Models.AssestLibrary Imglibrary = new AssestLibrary(); DatabaseRepository dbr = new DatabaseRepository(_logger, _env); //long len = (new System.IO.FileInfo(filename)).Length; Imglibrary.UserId = userId; Imglibrary.ImageName = imgName; Imglibrary.ImagePath = filename; Imglibrary.ImageSize = 25; Imglibrary.Imageuploadeddate = DateTime.UtcNow; int SavedStatus = dbr.Add <Domain.Socioboard.Models.AssestLibrary>(Imglibrary); if (SavedStatus == 1) { return(Ok("Image saved successfully")); } else { return(BadRequest("Something went wrong")); } }