//removed "magic string" converting the kit view model into a kit object //have to add kitId now because it is not new anymore public ActionResult Edit(KitViewModel kvmodel) { var kit = new Kit { KitId = kvmodel.Kit.KitId, Title = kvmodel.Kit.Title, Description = kvmodel.Kit.Description, Grade = kvmodel.Kit.Grade, ImageUrl = kvmodel.Kit.ImageUrl, Price = kvmodel.Kit.Price, DateAdded = kvmodel.Kit.DateAdded, Branch = kvmodel.Kit.Branch, BranchId = kvmodel.Kit.BranchId, PublicationDate = kvmodel.Kit.PublicationDate, LengthInMinutes = kvmodel.Kit.LengthInMinutes }; if (ModelState.IsValid) { db.Entry(kit).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } kvmodel.Branch = db.Branches.ToList(); return(View(kvmodel)); }
//need to make validate input false or get error here //don't like this because it's a magic string you'd have to remember to change. //public ActionResult Create([Bind(Include = "KitId,Title,Description,Grade,ImageUrl,Price,DateAdded,BranchId,PublicationDate,LengthInMinutes")] Kit kit) //not getting a kit object so instead we are getting the kit view model, then turning that into an object - manually converting a viewmodel object into an object of a class public ActionResult Create(KitViewModel kvmodel) { var kit = new Kit { Title = kvmodel.Kit.Title, Description = kvmodel.Kit.Description, Grade = kvmodel.Kit.Grade, ImageUrl = kvmodel.Kit.ImageUrl, Price = kvmodel.Kit.Price, DateAdded = kvmodel.Kit.DateAdded, Branch = kvmodel.Kit.Branch, BranchId = kvmodel.Kit.BranchId, PublicationDate = kvmodel.Kit.PublicationDate, LengthInMinutes = kvmodel.Kit.LengthInMinutes }; if (ModelState.IsValid) { db.Kits.Add(kit); db.SaveChanges(); return(RedirectToAction("Index")); } //get it from the database and pass the kit viewmodel into the view kvmodel.Branch = db.Branches.ToList(); return(View(kvmodel)); //don't like the viewbag as much as the viewmodel - you can associate the viewmodel strictly with the view //ViewBag.BranchId = new SelectList(db.Branches, "BranchId", "BranchName", kit.BranchId); //passing in viewmodel into the view instead of default kit }
public async Task <KitViewModel> GetBySku(string sku) { var view = new KitViewModel(); var kit = new DbKit(); kit = await _kitsRepository.GetByKit(sku); _logger.LogInformation("Successfully received kit by sku id"); view = _mapper.Map <KitViewModel>(kit); return(view); }
// GET: Kit/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Kit kit = db.Kits.Find(id); if (kit == null) { return(HttpNotFound()); } var model = new KitViewModel { Kit = kit, Branch = db.Branches.ToList() }; return(View(model)); }
public async Task <IActionResult> Edit(KitViewModel kit) { if (ModelState.IsValid) { var dto = new KitModel { Id = kit.Id, Title = kit.Title, ImageUrl = kit.ImageUrl, Manufacturer = kit.Manufacturer, KitType = kit.KitType, Size = kit.Size, Item = kit.Item }; await _kitsRepository.Add(dto); return(RedirectToAction(nameof(Index))); } return(View(kit)); }
// GET: Kit/Details/5 //passing a viewmodel instead of viewbag public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Kit kit = db.Kits.Find(id); if (kit == null) { return(HttpNotFound()); } var model = new KitViewModel { Kit = kit, Branch = db.Branches.ToList() }; //passing my viewmodel in instead of the kit obj return(View(model)); }
private void InitMarket() { var kitModel = new KitModel(dataController.GetCurrentKitData()); var kitViewModel = new KitViewModel(kitModel); var kitViewGO = Instantiate(kitPrefab); var kitView = kitViewGO.GetComponent <IKitView>(); kitView.BindViewModel(kitViewModel); var blocksData = dataController.GetCurrentKitData().Blocks; for (int i = 0; i < blocksData.Length; i++) { var blockModel = new BlockModel(blocksData[i]); var blockViewModel = new BlockViewModel(blockModel); var blockViewGO = Instantiate(blockPrefab); var blockView = blockViewGO.GetComponent <IBlockView>(); blockView.BindViewModel(blockViewModel); kitModel.SubscribeToUpdateModel(kitModel.UpdateModel); kitView.AddBlock(blockViewGO.transform); var productsData = blocksData[i].Products; for (int j = 0; j < productsData.Length; j++) { var productModel = new ProductModel(productsData[j]); var productViewModel = new ProductViewModel(productModel); var productViewGO = Instantiate(productPrefab); var productView = productViewGO.GetComponent <IProductView>(); productView.BindViewModel(productViewModel); blockModel.SubscribeToUpdateModel(blockModel.UpdateModel); blockView.AddProduct(productViewGO.transform); } } kitViewGO.transform.SetParent(uiParent); kitViewGO.transform.localPosition = Vector2.zero; }
// GET: Kit/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Kit kit = db.Kits.Find(id); if (kit == null) { return(HttpNotFound()); } //take out viewbag //ViewBag.BranchId = new SelectList(db.Branches, "BranchId", "BranchName", kit.BranchId); var model = new KitViewModel { Kit = kit, Branch = db.Branches.ToList() }; return(View(model)); }
public async Task <ActionResult <KitViewModel> > GetBySku(string sku) { if (String.IsNullOrEmpty(sku)) { return(NotFound()); } _logger.LogInformation("Getting list of kits"); var kit = new KitViewModel(); try { kit = await _kitService.GetBySku(sku); _logger.LogInformation("Successfully retrieved list of Variants"); } catch (Exception e) { _logger.LogError(e, "Error getting list of variants"); return(BadRequest(e)); } return(kit); }
public async Task <IActionResult> Kit(int id) { var settings = await _performerSchedulingService.GetSettingsAsync(); var schedulingStage = _performerSchedulingService.GetSchedulingStage(settings); if (schedulingStage < PsSchedulingStage.SchedulingPreview) { return(RedirectToAction(nameof(Index))); } PsKit kit; try { kit = await _performerSchedulingService.GetKitByIdAsync(id, includeAgeGroups : true, includeImages : true); } catch (GraException gex) { ShowAlertDanger("Unable to view kit: ", gex); return(RedirectToAction(nameof(Kits))); } var viewModel = new KitViewModel { Kit = kit, SchedulingOpen = schedulingStage == PsSchedulingStage.SchedulingOpen, CanSchedule = UserHasPermission(Permission.SchedulePerformers) }; if (kit.Images.Count > 0) { viewModel.ImagePath = _pathResolver.ResolveContentPath( kit.Images[0].Filename); } if (!string.IsNullOrWhiteSpace(kit.Website) && Uri.TryCreate(kit.Website, UriKind.Absolute, out Uri absoluteUri)) { viewModel.Uri = absoluteUri; } if (viewModel.SchedulingOpen) { viewModel.AgeGroupList = new SelectList(kit.AgeGroups, "Id", "Name"); var system = await _performerSchedulingService .GetSystemWithoutExcludedBranchesAsync(GetId(ClaimType.SystemId)); var branches = new List <Branch>(); foreach (var branch in system.Branches) { var branchSelections = await _performerSchedulingService .GetSelectionsByBranchIdAsync(branch.Id); if (branchSelections.Count >= settings.SelectionsPerBranch) { continue; } else { var selectedAgeGroups = branchSelections.Select(_ => _.AgeGroupId); var availableAgeGroups = kit.AgeGroups .Any(_ => !selectedAgeGroups.Contains(_.Id)); if (!availableAgeGroups) { continue; } } branches.Add(branch); } viewModel.BranchList = new SelectList(branches, "Id", "Name"); } var kitIndexList = await _performerSchedulingService.GetKitIndexListAsync(); var index = kitIndexList.IndexOf(id); viewModel.ReturnPage = (index / KitsPerPage) + 1; if (index != 0) { viewModel.PrevKit = kitIndexList[index - 1]; } if (kitIndexList.Count != index + 1) { viewModel.NextKit = kitIndexList[index + 1]; } return(View(viewModel)); }
public void Setup() { // Entities exampleKit1 = new DbKit { Id = "D3062", Name = "Urine Collection Kit", Sku = "D3062", Price = 118.0, ZREPrice = 118.0, Option = "10 Pack", WebActive = true, ImageUrl = "https://files.zymoresearch.com/product-images/D3062_Urine-Collection-Kit-with-Urine-Conditioning-Buffer.png", HighlightA = "Effectively preserves DNA and RNA in urine at ambient temperatures", HighlightB = "Facilitates pelleting of urine nucleic acids from large volume urine samples for nucleic acids purification", HighlightC = "Microbial inactivation", Description = "The Urine Collection Kit w/ Urine Conditioning Buffer (UCB) ensures nucleic acid stability in urine during sample storage/transport at ambient temperatures.", ShortDescription = "Kit for the collection and preservation of DNA and RNA in urine.", ProductType = ProductType.kit, ManufacturingOptions = new DbManufacturingOptions { Weight = 1.35, Height = 0, Width = 0, Length = 3.5 }, ShippingOptions = new DbShippingOptions { HazardShipping = false, ColdShipping = false, TypeIceShipping = null, ShippingTemp = 33 }, Documents = new DbProductDocuments { Protocol = "https://files.zymoresearch.com/protocols/_d4301_d4305_zymobiomics_dna_microprep_kit.pdf", Datasheet = "https://files.zymoresearch.com/datasheets/ds1704_zymobiomics_dna_extraction_data_sheet.pdf", SDS = "https://files.zymoresearch.com/sds/_d4301_zymobiomics_dna_microprep_kit.pdf" }, Components = new List <string> { "D3062-1", "D3061-1-8", "D3061-1-140" }, ModifiedOn = DateTime.Parse("019-04-29T22:23:58.657Z"), CreatedOn = DateTime.Parse("2019-04-29T22:23:58.657Z") }; exampleKit2 = new DbKit { Id = "R1002", Name = "YeaStar RNA Kit", Sku = "R1002", Price = 148.0, ZREPrice = 148.0, Option = "40 Preps", WebActive = true, ImageUrl = "https://files.zymoresearch.com/product-images/R1002_YeaStar-RNA-Kit.jpg", HighlightA = "<b>Simple:</b> Fast spin-column procedure yields pure yeast RNA without using glass beads or phenol.", HighlightB = "<b>Versatile:</b> Efficient RNA isolation from a broad spectrum of fungal species susceptible to Zymolyase.", HighlightC = "<b>High-Quality:</b> Isolated RNA is suitable for use in RT-PCR, Northern blotting, etc.", Description = "The YeaStar RNA Kit provides all the necessary reagents for RNA isolation from a broad spectrum of fungi including: <i>Aspergillus fumigatus</i>, <i>Aspergillus nidulans</i>, <i>Aspergillus nivens var. aureus</i>, <i>Candida albicans/<i>, Pichia pastoris</i>, <i>Saccharomyces cerevisiae</i>, <i>Schizosaccharomyces pombe</i>. Generally, the kit can be used for the purification of high-quality, total RNA from any fungus that can be lysed by yeast lytic enzyme. The kit facilitates the purification of 10-25 µg of total RNA from 1-1.5 ml of cultured cells using innovative Zymo-Spin column technology.", ShortDescription = "Simple spin-column solution for isolating RNA from yeast using Zymolyase.", ProductType = ProductType.kit, ManufacturingOptions = new DbManufacturingOptions { Weight = 0.8, Height = 0, Width = 0, Length = 7 }, ShippingOptions = new DbShippingOptions { HazardShipping = false, ColdShipping = false, TypeIceShipping = null, ShippingTemp = 23 }, Documents = new DbProductDocuments { Protocol = "https://files.zymoresearch.com/protocols/_d4301_d4305_zymobiomics_dna_microprep_kit.pdf", Datasheet = "https://files.zymoresearch.com/datasheets/ds1704_zymobiomics_dna_extraction_data_sheet.pdf", SDS = "https://files.zymoresearch.com/sds/_d4301_zymobiomics_dna_microprep_kit.pdf" }, Components = new List <string> { "W1001-6", "R1001-1", "R1001-2", "R1003-3-6", "C1001-50", "C1006-50-G" }, ModifiedOn = DateTime.Parse("2019-03-28T16:27:46.807Z"), CreatedOn = DateTime.Parse("2019-03-28T16:27:46.807Z") }; exampleKit3 = new DbKit { Id = "T2001", Name = "", Sku = "", Price = 104, ZREPrice = 104, Option = "", WebActive = true, ImageUrl = "", HighlightA = "", HighlightB = "", HighlightC = "", Description = "", ShortDescription = "", ProductType = ProductType.kit, ManufacturingOptions = new DbManufacturingOptions { Weight = 0.5, Height = 0, Width = 0, Length = 4.3 }, ShippingOptions = new DbShippingOptions { HazardShipping = false, ColdShipping = false, TypeIceShipping = null, ShippingTemp = 23 }, Documents = new DbProductDocuments { Protocol = "https://files.zymoresearch.com/protocols/_d4301_d4305_zymobiomics_dna_microprep_kit.pdf", Datasheet = "https://files.zymoresearch.com/datasheets/ds1704_zymobiomics_dna_extraction_data_sheet.pdf", SDS = "https://files.zymoresearch.com/sds/_d4301_zymobiomics_dna_microprep_kit.pdf" }, Components = new List <string> { "T2002", "T2003", "T2004" }, ModifiedOn = DateTime.Parse("2019-01-30T22:47:54.35Z"), CreatedOn = DateTime.Parse("2019-01-30T22:47:54.35Z") }; kitList = new List <DbKit> { exampleKit1, exampleKit2, exampleKit3 }; viewList = Mapper.Map <List <KitViewModel> >(kitList); // Service Interface Implementation mockServices.Setup(s => s.GetAll()).ReturnsAsync(viewList); mockServices.Setup(s => s.GetBySku(It.IsAny <string>())).ReturnsAsync( (string sku) => { DbKit model = kitList.Where(m => m.Id == sku).FirstOrDefault(); KitViewModel newModel = null; if (model != null) { newModel = Mapper.Map <KitViewModel>(model); } return(newModel); } ); // mockServices.Setup(s => s.GetKitComponents(It.IsAny<string>())).ReturnsAsync( // (string kitSku) => // { // DbKit model = kitList.Where(m => m.Id == kitSku).FirstOrDefault(); // DbKit newModel = null; // List<DbVariant> componentList = new List<DbVariant>(); // if (model != null) // { // newModel = new DbKit // { // Id = model.Id, // Name = model.Name, // Components = model.Components // }; // } // foreach(var sku in newModel.Components) // { // // Get components // // Currently, components have not been created // } // return componentList; // } // ); // THIS IS ESSENTIAL TO USE THE MOCK SERVICES CREATED ABOVE // SINCE WE USE KITSERVICE, WILL RETURN NULL EXCEPTION kitService = mockServices.Object; }