public void CanInsertMobileSuit() { Mobile_Suit MobileSuit = new Mobile_Suit(); var repo = new MobileSuitRepositoryADO(); MobileSuit.UserID = "11111111-1111-1111-1111-111111111111"; MobileSuit.BodyStyleID = 1; MobileSuit.ColorID = 2; MobileSuit.Interior = 2; MobileSuit.Description = "Custom Red Zaku II, Customized for peak performance for commanders of the Zeon army. 3x Faster than the base model with an added shield attatchment. "; MobileSuit.MakeModelID = 2; MobileSuit.MSRP = 120000; MobileSuit.SalePrice = 100000; MobileSuit.SerialNumber = "0123456789"; MobileSuit.TypeID = 2; MobileSuit.WeaponID = 1; MobileSuit.Year = 0079; MobileSuit.Name = "Zaku II Commander Type"; MobileSuit.Image = "Placeholder.Jpeg"; MobileSuit.CenturyID = 1; MobileSuit.Featured = true; repo.Insert(MobileSuit); Assert.AreEqual(7, MobileSuit.InventoryNumber); }
public ActionResult Add(AddMobileSuitViewModel model) { var user = User.Identity; model.MobileSuit.UserID = user.GetUserId(); var MakeModelCheck = new MakeModelrepo(); var test = MakeModelCheck.GetByBoth(model.MobileSuit.MakeID, model.MobileSuit.ModelID); if (test.MakeModelID == 0) { var temp = MakeModelCheck.Insert(model.MobileSuit.MakeID, model.MobileSuit.ModelID); model.MobileSuit.MakeModelID = temp; } else { model.MobileSuit.MakeModelID = test.MakeModelID; } if (ModelState.IsValid) { var repo = new MobileSuitRepositoryADO(); try { var savepath = Server.MapPath("~/Images"); string fileName = Path.GetFileNameWithoutExtension(model.ImageUpload.FileName); string extension = Path.GetExtension(model.ImageUpload.FileName); var filePath = Path.Combine(savepath, fileName + extension); int counter = 1; while (System.IO.File.Exists(filePath)) { filePath = Path.Combine(savepath, fileName + counter.ToString() + extension); counter++; } model.ImageUpload.SaveAs(filePath); model.MobileSuit.Image = Path.GetFileName(filePath); repo.Insert(model.MobileSuit); return(RedirectToAction("MobileSuits", "Admin")); } catch (Exception ex) { throw ex; } } else { var model2 = new AddMobileSuitViewModel(); var TypeRepo = new TypeRepositoryADO(); var BodyRepo = new BodyStylesRepoADO(); var CenturyRepo = new CenturyRepoADO(); var ColorRepo = new ColorRepoADO(); var ModelRepo = new ModelRepoADO(); var MakeRepo = new MakeRepoADO(); var WeaponRepo = new WeaponRepoADO(); model2.Types = new SelectList(TypeRepo.GetAll(), "TypeId", "Name"); model2.BodyStyles = new SelectList(BodyRepo.GetAll(), "BodyStyleId", "Name"); model2.Centuries = new SelectList(CenturyRepo.GetAll(), "CenturyId", "CenturyName"); model2.Colors = new SelectList(ColorRepo.GetAll(), "ColorId", "Name"); model2.Models = new SelectList(ModelRepo.GetAll(), "ModelId", "Name"); model2.Makes = new SelectList(MakeRepo.GetAll(), "MakeId", "Name"); model2.Weapons = new SelectList(WeaponRepo.GetAll(), "WeaponId", "WeaponName"); return(View(model2)); } }