public async Task <IActionResult> Post([FromBody] BrewViewModel brewForCreation) { if (brewForCreation == null) { return(BadRequest()); } var brewForRepo = _mapper.Map <Brew>(brewForCreation); await _brewRepository.CreateBrewAsync(brewForRepo); var eventMessage = new SeedCatalogWithNewBrewIntegrationEvent( brewForRepo.BrewName, brewForRepo.BrewId, brewForRepo.StockQuantity, (int)Math.Round((double)(brewForRepo.StockQuantity / 3), 0) ); try { _eventBus.Publish(eventMessage); } catch (Exception ex) { //_logger.Logit } return(CreatedAtAction(nameof(Get), new { id = brewForRepo.BrewId })); }
// GET: Brews/Delete/5 public ActionResult Delete(string id) { var brew = this.manager.Find(Guid.Parse(id)); var model = new BrewViewModel { Name = brew.Name }; return(View(model)); }
public void BrewViewModel_ShouldSubscribeToTheMessageWatcher() { messageWatcher.Setup(x => x.Subscribe(brewViewModel, It.IsAny<String>())); var message1 = "Containment Vessel Full"; var message2 = "Containment Vessel Not Ready"; var message3 = "Water Source Empty"; brewViewModel = new BrewViewModel(messageSender.Object, messageWatcher.Object); messageWatcher.Verify(x => x.Subscribe(brewViewModel, message1), Times.Once); messageWatcher.Verify(x => x.Subscribe(brewViewModel, message2), Times.Once); messageWatcher.Verify(x => x.Subscribe(brewViewModel, message3), Times.Once); }
// GET: Brews/Details/5 public ActionResult Details(string id) { var domModel = this.manager.Find(Guid.Parse(id)); var model = new BrewViewModel { Id = id, Name = domModel.Name, Description = domModel.Description, RecipeName = domModel.RecipeName }; return(View(model)); }
public ActionResult Create(int recipeId) { var recipe = RecipeService.GetRecipe(recipeId); var model = new BrewViewModel() { RecipeId = recipeId, Title = recipe.Title, Status = "Created", Annotations = string.Format("> This brew is based on the recipe [{0}]({1})", recipe.Title, Url.Action("Details", "Recipes", new { id = recipeId })) }; model.Statuses.First().Selected = true; return(View(model)); }
public ActionResult Delete(BrewViewModel model) { var id = Guid.Parse(model.Id); try { this.manager.Delete(id); return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public ActionResult Link_Post(int id, BrewViewModel postedModel) { int brewId = id; if (!string.IsNullOrEmpty(postedModel.SensorId)) { BrewService.LinkSensor(brewId, postedModel.SensorId); } else { var brew = BrewService.GetBrew(id); BrewService.UnlinkSensor(brewId, brew.SensorId); } return(RedirectToAction("Details", new { id = brewId })); }
public ActionResult Create_Post(int recipeId, BrewViewModel postedModel) { if (ModelState.IsValid) { var brew = BrewService.CreateBrew(User.Identity.Name, recipeId, postedModel.Title, postedModel.Annotations, (BrewStatus)Enum.Parse(typeof(BrewStatus), postedModel.Status)); if (postedModel.IsPublic) { BrewService.MakePublic(brew.Id); } else { BrewService.MakePrivate(brew.Id); } return(RedirectToAction("Details", new { id = brew.Id })); } postedModel.Statuses.First(s => s.Text == postedModel.Status).Selected = true; return(View(postedModel)); }
public void Setup() { messageSender = new Mock<IMessageSender<String>>(); messageWatcher = new Mock<IMessageWatcher<String>>(); brewViewModel = new BrewViewModel(messageSender.Object, messageWatcher.Object); }