コード例 #1
0
        private HttpResponseMessage ProcessExistingFarmRecord(HttpRequestMessage request, FarmDTO cqDto, int contactId, string key, int companyId, int UserId)
        {
            var ur = new FarmRepository();
            var Farm = new Farm();
            Farm = ur.GetById(contactId);
            //  is the Farm eligible to update the prospect?

            var validationErrors = GetValidationErrors(ur, Farm, cqDto, companyId, UserId);
            if (validationErrors.Any())
            {
                return ProcessValidationErrors(request, validationErrors, key);
            }
            //  no validation errors...
            ur.Save(Farm);
            cqDto.Key = key;
            return request.CreateResponse(HttpStatusCode.Accepted, cqDto);
        }
コード例 #2
0
        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;
        }
コード例 #3
0
 private HttpResponseMessage ChangeThisFarmStatus(HttpRequestMessage request, FarmDTO cqDto, int contactId, string key, int companyId, int UserId)
 {
     var ur = new FarmRepository();
     var Farm = new Farm();
     Farm = ur.GetById(contactId);
     Farm.StatusId = int.Parse(cqDto.StatusId);
     //  no validation errors...
     ur.Save(Farm);
     cqDto.Key = key;
     return request.CreateResponse(HttpStatusCode.Accepted, cqDto);
 }