public async Task <IActionResult> EditTypesOfPrinting(TypeEditViewModel typeView) { if (typeView.TypeImage != null) { using (var memoryStream = new MemoryStream()) { await typeView.TypeImage.CopyToAsync(memoryStream); typeView.Type.Image = memoryStream.ToArray(); typeView.Type.ImageMimeType = typeView.TypeImage.ContentType; } } if (ModelState.IsValid) { var category = new TypesOfPrinting { Title = typeView.Type.Title, Description = typeView.Type.Description, Image = typeView.Type.Image }; typeRepository.SaveType(typeView.Type); TempData["message"] = $"{typeView.Type.Title} has been saved"; return(RedirectToAction("InformationList")); } else { // there is something wrong with the data values return(View(typeView)); } }
public IActionResult DeleteType(int typeId) { TypesOfPrinting deletedType = typeRepository.DeleteType(typeId); if (deletedType != null) { TempData["message"] = $"{deletedType.Title} was deleted"; } return(RedirectToAction("InformationList")); }
public FileContentResult GetImageType(TypesOfPrinting item) { TypesOfPrinting type = typeRepository.Types .FirstOrDefault(g => g.Id == item.Id); if (type != null) { return(File(type.Image, type.ImageMimeType)); } else { return(null); } }