public async Task <IHttpActionResult> Post(int apiaryId, int hiveId, InspectionModel inspectionModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Inspection Model is not valid"));
            }

            try
            {
                using (var context = new BeeAppContext())
                {
                    if (await _ensurer.EnsureHiveBelongsToApiary(context, apiaryId, hiveId, _applicationUserId))
                    {
                        context.Inspections.Add(new Inspection
                        {
                            Date              = inspectionModel.Date,
                            Name              = inspectionModel.Name,
                            Strength          = inspectionModel.Strength,
                            Temper            = inspectionModel.Temper,
                            Disease           = inspectionModel.Disease,
                            FramesBees        = inspectionModel.FramesBees,
                            FramesHoney       = inspectionModel.FramesHoney,
                            FramesHoneySupers = inspectionModel.FramesHoneySupers,
                            Drones            = inspectionModel.Drones,
                            DroneCells        = inspectionModel.DroneCells,
                            HiveId            = hiveId
                        });

                        // Save
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            // Return
            return(Ok(inspectionModel));
        }
        public async Task <IHttpActionResult> Post(int apiaryId, int hiveId, FeedingModel feedingModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Feeding Model is not valid"));
            }

            try
            {
                using (var context = new BeeAppContext())
                {
                    if (await _ensurer.EnsureHiveBelongsToApiary(context, apiaryId, hiveId, _applicationUserId))
                    {
                        context.Feedings.Add(new Feeding
                        {
                            Name     = feedingModel.Name,
                            Date     = feedingModel.Date,
                            Product  = feedingModel.Product,
                            Quantity = feedingModel.Quantity,
                            Unit     = feedingModel.Unit,
                            Note     = feedingModel.Note,
                            HiveId   = hiveId
                        });

                        // Save
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            // Return
            return(Ok(feedingModel));
        }
Esempio n. 3
0
        public async Task <IHttpActionResult> Post(int apiaryId, int hiveId, QueenModel queenModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Queen Model is not valid"));
            }

            try
            {
                using (var context = new BeeAppContext())
                {
                    if (await _ensurer.EnsureHiveBelongsToApiary(context, apiaryId, hiveId, _applicationUserId))
                    {
                        context.Queens.Add(new Queen
                        {
                            Name   = queenModel.Name,
                            Date   = queenModel.Date,
                            Breed  = queenModel.Breed,
                            Colour = queenModel.Colour,
                            State  = queenModel.State,
                            Status = queenModel.Status,
                            HiveId = hiveId
                        });

                        // Save
                        context.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            // Return
            return(Ok(queenModel));
        }