public IActionResult Create(int?subcatid, int?catid) { SubCatGalleryViewModel model = new SubCatGalleryViewModel { IsMainImage = true, SubCategoryID = subcatid, CategoryID = catid }; GetCategories(); //GetSubCategories(catid); GetCatIDSubCatID(subcatid, catid); return(View(model)); }
public async Task <IActionResult> FileUpload(IList <IFormFile> files, IFormCollection data) { //try //{ _logger.LogInformation("***********************************"); _logger.LogInformation("FileUpload Started"); var CategoryID = Convert.ToInt32(data["CategoryID"]); var SubCategoryID = Convert.ToInt32(data["SubCategoryID"]); int _count = TempData["LastOrderNo"] != null ? (int)TempData["LastOrderNo"] + 1 : 1; _logger.LogInformation("_count: " + _count); foreach (IFormFile source in files) { string filename = ContentDispositionHeaderValue.Parse(source.ContentDisposition).FileName.ToString().Trim('"'); filename = this.EnsureCorrectFilename(filename); _logger.LogInformation("filename: " + filename); // "T_ for Thumbnail; O_ for Original SubCatGalleryViewModel model = new SubCatGalleryViewModel { CategoryID = CategoryID, SubCategoryID = SubCategoryID, ThumbNailSizeImage = "T_" + filename, OriginalImage = "O_" + filename, IsMainImage = false, Order = _count }; if (SaveSubCategoryDetails(model)) { // Save Thumnail Image ResizeImage(source, GetPathAndFilename("T_" + filename, SubCategoryID)); // Save Original Image using (FileStream output = System.IO.File.Create(GetPathAndFilename("O_" + filename, SubCategoryID))) { await source.CopyToAsync(output); } } _count++; } _logger.LogInformation("Uploaded"); return(Ok("Uploaded")); //} //catch (Exception ex) //{ // _logger.LogInformation("Exception ex" + ex.Message); // return BadRequest(ex.Message); //} }
/// <summary> /// Save & Update Sub Category Details with Post & Put Methods of the Web APIs. /// </summary> /// <param name="model"></param> /// <param name="action"></param> /// <returns></returns> private bool SaveSubCategoryDetails(SubCatGalleryViewModel model) { try { var response = generateAPIResponse.SubCatGalleryViewRepo.Save("subcatgallery", model).Result; if (response) { TempData["Message"] = "Sub Category record has been created successfully."; TempData["Class"] = "text-success"; return(true); } else { TempData["Message"] = "Something went wrong"; } } catch (Exception ex) { TempData["Message"] = "Something went wrong: " + ex.Message; } return(false); }