public HttpResponseMessage Post(EggProduction value)
        {
            HttpResponseMessage response = null;

            ValidateModel(value);

            if (!ModelState.IsValid)
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, GetModelErrors());
                return(response);
            }

            try
            {
                service.Save(value);
                response = Request.CreateResponse(HttpStatusCode.Created, value);
                string uri = Url.Link("DefaultApi", new { id = value.Id });
                response.Headers.Location = new Uri(uri);
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message);
            }

            return(response);
        }
        public void Can_SaveNewEggProduction()
        {
            var house = new Models.HenHouse
            {
                Id           = Guid.NewGuid(),
                Name         = "House 1",
                PurchaseCost = 1,
                Depreciation = 1,
                YearUsage    = 1,
                Active       = true
            };

            using (var conn = factory.OpenDbConnection())
            {
                conn.InsertParam(house);
            }

            var production = new Models.EggProduction
            {
                Date    = DateTime.Today,
                Details = new List <EggProductionDetail>()
                {
                    new Models.EggProductionDetail
                    {
                        CrackedEggCount = 1,
                        Fcr             = 1,
                        GoodEggCount    = 1,
                        HouseId         = house.Id,
                        RetailQuantity  = 1.2m
                    }
                }
            };

            service.Save(production);
            using (var conn = factory.OpenDbConnection())
            {
                var data    = conn.FirstOrDefault <Models.Data.EggProduction>(e => e.Date == production.Date);
                var details = conn.Where <Models.Data.EggProductionDetail>(new { ProductionId = data.Id });
                Compare(data, details, production);
            }
        }
 public override void Execute(object parameter)
 {
     try
     {
         service.Save(Production);
         broker.Publish(CommonMessages.SaveEggProductionSuccess, Production);
     }
     catch (Exception ex)
     {
         broker.Publish(CommonMessages.SaveEggProductionFailed, new Error
         {
             Data      = Production,
             Exception = ex
         });
     }
 }