public IActionResult Create(Beer entidade) { if (!ModelState.IsValid) { return(View(entidade)); } _beerRepository.Add(entidade); //Colocar um Toaster aqui para avisar que ok return(RedirectToAction("index")); }
public IActionResult Create([FromBody] Beer item) { if (item == null) { item = new Beer(); //return BadRequest(); } _beerRepository.Add(item); return(CreatedAtRoute("GetBeer", new { id = item.Id }, item)); }
public string CreateBeer(string name, double abv, double baScore, string styleId, string breweryId) { var id = string.Empty; id = _beerRepository.NextIdentity(); var beer = new Beer(id, name) { ABV = abv, BAScore = baScore, BreweryId = breweryId, RPScore = 0, StyleId = styleId }; _beerRepository.Add(beer); return(id); }
public IActionResult Create(string name, string type, int price, IFormFile picture) { byte[] pictureArray = new byte[0]; Debug.WriteLine(picture); if (picture.Length > 0) { using (var fileStream = picture.OpenReadStream()) using (var ms = new MemoryStream()) { fileStream.CopyTo(ms); pictureArray = ms.ToArray(); } } Beer newBeer = new Models.Beer(name, type, price, pictureArray); beerRepo.Add(newBeer); return(RedirectToAction("Index")); }
public Beer Post([FromBody] Beer beer) { var addedBeer = _beerRepository.Add(beer); return(addedBeer); }
public void Add_Gets_Added() { var newBeer = new Beer { Name = "TestBeer" + DateTime.Now.Ticks, BeerStyleId = 1, ForkeOfId = 17, SRM = new SRM { Daniels = 1, Morey = 1, Mosher = 1, Standard = 1 }, ABV = new ABV { Advanced = 2, AdvancedAlternative = 2, AlternativeSimple = 2, Miller = 2, Simple = 2, Standard = 2, }, IBU = new IBU { Rager = 20, Standard = 20, Tinseth = 25 }, }; var newRecipe = new Recipe { Volume = 20, Notes = "SOmething", Efficiency = 75, MashSteps = new List <MashStep> { new MashStep { StepNumber = 1, Temperature = 56, Type = "Infusion", Notes = "Notes", Length = 10, Volume = 20, Fermentables = new List <MashStepFermentable> { new MashStepFermentable { Amount = 1000, Lovibond = 23, PPG = 12, FermentableId = 2 }, new MashStepFermentable { Amount = 1000, Lovibond = 23, PPG = 12, FermentableId = 1 }, }, Hops = new List <MashStepHop> { new MashStepHop { Amount = 30, AAValue = 5, HopFormId = 1, HopId = 1, } }, Others = new List <MashStepOther> { new MashStepOther { Amount = 10, OtherId = 1, } } }, new MashStep { StepNumber = 2, Temperature = 56, Type = "Infusion", Notes = "Notes", Length = 10, Volume = 20 } }, BoilSteps = new List <BoilStep> { new BoilStep { StepNumber = 3, Volume = 21, Notes = "Notes", Length = 60, Fermentables = new List <BoilStepFermentable> { new BoilStepFermentable { Amount = 1000, Lovibond = 23, PPG = 12, FermentableId = 2 }, new BoilStepFermentable { Amount = 1000, Lovibond = 23, PPG = 12, FermentableId = 1 }, }, Hops = new List <BoilStepHop> { new BoilStepHop { Amount = 30, AAValue = 5, HopFormId = 1, HopId = 1, } }, Others = new List <BoilStepOther> { new BoilStepOther { Amount = 10, OtherId = 1, } } } }, FermentationSteps = new List <FermentationStep> { new FermentationStep { StepNumber = 4, Length = 14, Temperature = 21, Notes = "Somehting more", Volume = 19, Fermentables = new List <FermentationStepFermentable> { new FermentationStepFermentable { Amount = 1000, Lovibond = 23, PPG = 12, FermentableId = 2 }, new FermentationStepFermentable { Amount = 1000, Lovibond = 23, PPG = 12, FermentableId = 1 }, }, Hops = new List <FermentationStepHop> { new FermentationStepHop { Amount = 30, AAValue = 5, HopFormId = 1, HopId = 1, } }, Others = new List <FermentationStepOther> { new FermentationStepOther { Amount = 10, OtherId = 1, } }, Yeasts = new List <FermentationStepYeast> { new FermentationStepYeast { Amount = 1, YeastId = 1, } } } } }; newBeer.Recipe = newRecipe; _beerRepository.Add(newBeer); var beer = _beerRepository.GetSingle(newBeer.BeerId); Assert.NotNull(beer); Assert.True(beer.Name.Any()); }
public void Add(Beer entity) { _repo.Add(entity); }