Esempio n. 1
0
        public AlcoholModel GetAlcoholByVolume(double startingGravity, double endingGravity, double temperatureFahrenheit)
        {
            ICalculateAlcoholFactory alcoholFactory = new CalculateAlcoholFactory();
            var alcoholCalculator = alcoholFactory.GetCalculator(new AlcoholByVolumeStrategy());

            alcoholCalculator.StartingGravity = startingGravity;
            alcoholCalculator.EndingGravity   = endingGravity;
            AlcoholModel model = new AlcoholModel();

            model.AlcoholByVolume = alcoholCalculator.Calculate();
            return(model);
        }
Esempio n. 2
0
 public ActionResult Post(AlcoholModel model)
 {
     try
     {
         Alcohol result = _repository.Add(model);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(StatusCode(StatusCodes.Status500InternalServerError, "Failed database"));
     }
 }
        public Alcohol Add(AlcoholModel model)
        {
            Alcohol alcohol = new Alcohol
            {
                Name            = model.Model_Name,
                Alcohol_type    = model.Model_Alcohol_type,
                Alcohol_degree  = model.Model_Alcohol_degree,
                Pulled_from     = model.Model_Pulled_from,
                Year_of_alcohol = model.Model_Year_of_alcohol,
                Made_In         = model.Model_Made_In
            };

            _context.Add(alcohol);
            _context.SaveChanges();

            return(alcohol);
        }
Esempio n. 4
0
        public ActionResult Put(AlcoholModel model)
        {
            try
            {
                var alcohol = _repository.Get_Alcohol_byId(model.Model_Id);
                if (alcohol == null)
                {
                    return(NotFound());
                }

                _mapper.Map(model, alcohol);
                _repository.SaveChanges();
                return(Ok(alcohol));
            }
            catch (Exception ex)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "Failed database"));
            }
        }