private List<DbValidationError> GetHarvestValidationErrors(HarvestRepository pr, Harvest contact, HarvestDTO cqDto, int companyId, int PondId) { contact.ProcessRecord(cqDto); return pr.Validate(contact); }
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; }
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); }