示例#1
0
 public IActionResult AddCat(AddCatViewModel model)
 {
     if (ModelState.IsValid)
     {
         string uniqueFileName = null;
         if (model.Image != null)
         {
             string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "imgs");
             uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Image.FileName;
             string filePath = Path.Combine(uploadsFolder, uniqueFileName);
             model.Image.CopyTo(new FileStream(filePath, FileMode.Create));
         }
         Cat newCat = new Cat
         {
             Name      = model.Name,
             Age       = model.Age,
             Gender    = model.Gender,
             Bio       = model.Bio,
             ImagePath = uniqueFileName
         };
         _catRepo.AddCat(newCat);
         return(RedirectToAction("Details", new { id = newCat.CatId }));
     }
     return(View());
 }
示例#2
0
 public void AddCat(Cat cat)
 {
     repository.AddCat(cat);
 }