private HttpResponseMessage ProcessNewFarmRecord(HttpRequestMessage request, FarmDTO uDto, string key, int companyId, int UserId) { var ur = new FarmRepository(); var Farm = new Farm(); bool newfromsetup; if (uDto.CompanyId == null) { uDto.CompanyId = companyId.ToString(); newfromsetup = false; } else { newfromsetup = true; } var validationErrors = GetValidationErrors(ur, Farm, uDto, companyId, UserId); if (validationErrors.Any()) { return ProcessValidationErrors(request, validationErrors, key); } // no validation errors... //Farm.CompanyId = companyId; Farm = ur.Save(Farm); if (newfromsetup) { var aur = new AppUserRepository(); var users = aur.GetByCompanyId(Farm.CompanyId); foreach (User user in users) { var ufr = new UserFarmRepository(); var ufarm = new UserFarm(); //ur = aur.GetByUserAndRoleIds(contactId, int.Parse(cqDto.RoleID)); ufarm.UserId = user.UserId; ufarm.FarmId= Farm.FarmId; ufarm.StatusId = 1; ufr.Save(ufarm); } } uDto.Key = key; uDto.FarmId = Farm.FarmId.ToString(); var response = request.CreateResponse(HttpStatusCode.Created, uDto); response.Headers.Location = new Uri(Url.Link("Default", new { id = Farm.FarmId })); return response; }