Ejemplo n.º 1
0
        public HttpResponseMessage HarvestPond([FromBody] HarvestDTO 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 hr     = new HarvestRepository();
                var harv   = new Harvest();
                var errors = ValidateDtoData(uDto, harv);
                if (errors.Any())
                {
                    return(ProcessValidationErrors(Request, errors, key));
                }

                return(ProcessNewHarvestRecord(Request, uDto, 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));
        }
        public async Task Put(int id, [FromBody] HarvestDTO value)
        {
            var harvestEntity = await _service.Find(id);

            Harvest newEntity = _mapper.Map(value, harvestEntity);

            await _service.Update(newEntity);
        }
        public async Task Post([FromBody] HarvestDTO value)
        {
            Harvest entity = _mapper.Map <HarvestDTO, Harvest>(value);

            await _service.Add(entity);
        }
        public async Task <HarvestDTO> Get(int id)
        {
            HarvestDTO harvestDTO = _mapper.Map <Harvest, HarvestDTO>(await _service.Find(id));

            return(harvestDTO);
        }
Ejemplo n.º 5
0
        private HttpResponseMessage ProcessNewHarvestRecord(HttpRequestMessage request, HarvestDTO uDto, string key, int companyId, int UserId)
        {
            var hr   = new HarvestRepository();
            var harv = new Harvest();

            var validationErrors = GetHarvestValidationErrors(hr, harv, uDto, companyId, UserId);

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

            harv           = hr.Save(harv);
            uDto.Key       = key;
            uDto.HarvestId = harv.HarvestId.ToString();
            var response = request.CreateResponse(HttpStatusCode.Created, uDto);

            response.Headers.Location = new Uri(Url.Link("Default", new
            {
                id = harv.HarvestId
            }));
            return(response);
        }
Ejemplo n.º 6
0
        private List <DbValidationError> GetHarvestValidationErrors(HarvestRepository pr, Harvest contact, HarvestDTO cqDto, int companyId, int PondId)
        {
            contact.ProcessRecord(cqDto);

            return(pr.Validate(contact));
        }