public HttpResponseMessage FeedAddOrEdit([FromBody] FeedingDTO uDto)
        {
            string key;
            var ur = new AppUserRepository();
            var companyId = 0;
            var UserId = ur.ValidateUser(uDto.Key, out key, ref companyId);

            AppUserRoleRepository aur = new AppUserRoleRepository();

            if (UserId > 0 && aur.IsInRole(UserId, "Chowtime"))
            {
                var thisuser = ur.GetById(UserId);
                var pr = new PondRepository();
                int thisfarm = pr.GetById(int.Parse(uDto.PondId)).FarmId;
                int UsersFarmId = thisuser.UserFarms.Where(x => x.FarmId == thisfarm).SingleOrDefault().UserFarmId;
                uDto.UsersFarmId = UsersFarmId.ToString();

                var feed = new Feeding();
                var errors = ValidateDtoData(uDto, feed);
                if (errors.Any())
                {
                    return ProcessValidationErrors(Request, errors, key);
                }
                var NEFeedingId = 0;
                if (int.TryParse(uDto.FeedingId, out NEFeedingId))
                {
                    if (NEFeedingId == -1)
                    {
                        //  creating new Pond record
                        return ProcessNewFeedRecord(Request, uDto, key, companyId, UserId);
                    }
                    else
                    {
                        //  editing existing Pond record
                        return ProcessExistingFeedRecord(Request, uDto, NEFeedingId, key, companyId, UserId);
                    }
                }
                //  no idea what this is
                var msg = "invalid data structure submitted";
                return Request.CreateResponse(HttpStatusCode.BadRequest, msg);
            }
            var message = "validation failed";
            return Request.CreateResponse(HttpStatusCode.NotFound, message);
        }
        private HttpResponseMessage ProcessNewFeedRecord(HttpRequestMessage request, FeedingDTO uDto, string key, int companyId, int UserId)
        {
            var ur = new FeedingRepository();
            var o2 = new Feeding();

            var validationErrors = GetFeedValidationErrors(ur, o2, uDto, companyId, UserId);

            if (validationErrors.Any())
            {
                return ProcessValidationErrors(request, validationErrors, key);
            }
            //  no validation errors...
            //Pond.CompanyId = companyId;

            o2 = ur.Save(o2);

            uDto.Key = key;
            var response = request.CreateResponse(HttpStatusCode.Created, uDto);
            response.Headers.Location = new Uri(Url.Link("Default", new
            {
                id = o2.FeedingId
            }));
            return response;
        }
        private HttpResponseMessage ProcessExistingFeedRecord(HttpRequestMessage request, FeedingDTO cqDto, int contactId, string key, int companyId, int UserId)
        {
            var o2r = new FeedingRepository();
            var o2 = new Feeding();
            o2 = o2r.GetById(contactId);
            //  is the Pond eligible to update the prospect?

            var validationErrors = GetFeedValidationErrors(o2r, o2, cqDto, companyId, UserId);
            if (validationErrors.Any())
            {
                return ProcessValidationErrors(request, validationErrors, key);
            }
            //  no validation errors...
            o2r.Save(o2);
            cqDto.Key = key;
            return request.CreateResponse(HttpStatusCode.Accepted, cqDto);
        }
        private List<DbValidationError> GetFeedValidationErrors(FeedingRepository pr, Feeding contact, FeedingDTO cqDto, int companyId, int PondId)
        {
            contact.ProcessRecord(cqDto);

            return pr.Validate(contact);
        }