public FarmAnimalStock(LivestockCategory livestockCategory)
 {
     Name        = livestockCategory.AnimalShop.Name;
     Description = livestockCategory.AnimalShop.Description;
     Icon        = GetDefaultIconPath(livestockCategory.ToString());
     Exclude     = livestockCategory.AnimalShop.Exclude == null || !livestockCategory.AnimalShop.Exclude.Any()
 ? new List <string>()
 : livestockCategory.AnimalShop.Exclude.Select(o => o.ToString()).ToList();
 }
 public FarmAnimalCategory(string assetSourceDirectory, LivestockCategory category)
 {
     Category   = category.ToString();
     Types      = category.Types.Select(o => new FarmAnimalType(o)).ToList();
     Buildings  = category.Buildings.ToList();
     AnimalShop = category.CanBePurchased() ? new FarmAnimalStock(category) : null;
     if (!CanBePurchased())
     {
         return;
     }
     AnimalShop.Icon = Path.Combine(assetSourceDirectory, AnimalShop.Icon);
 }
Example #3
0
 public ActionResult Add(LivestockCategory category, HttpPostedFileBase file)
 {
     category.CreatorID    = User.Identity.GetUserId <int>();
     category.CreationDate = DateTime.UtcNow;
     if (DB.LivestockCategories.Any(c => c.Name.Contains(category.Name)))
     {
         ModelState.AddModelError(nameof(category.Name), "The  category already exists");
     }
     if (ModelState.IsValid)
     {
         DB.LivestockCategories.Add(category);
         DB.SaveChanges();
         return(RedirectToAction(nameof(Details), new { category.ID }));
     }
     ViewBag.branches = new SelectList(DB.Branches.OrderBy(c => c.Name), nameof(Branch.ID), nameof(Branch.Name), category.BranchID);
     ViewBag.Title    = "Add a livestock category";
     return(View(category));
 }