コード例 #1
0
 private void AdjustRecord(RentalAgreementCondition item)
 {
     if (item != null && item.RentalAgreement != null)
     {
         item.RentalAgreement = _context.RentalAgreements.FirstOrDefault(a => a.Id == item.RentalAgreement.Id);
     }
 }
コード例 #2
0
        /// <summary>
        /// Create rental agreement condition
        /// </summary>
        /// <param name="item"></param>
        /// <response code="201">Project created</response>
        public virtual IActionResult RentalagreementconditionsPostAsync(RentalAgreementCondition item)
        {
            if (item != null)
            {
                AdjustRecord(item);

                bool exists = _context.RentalAgreementConditions.Any(a => a.Id == item.Id);

                if (exists)
                {
                    _context.RentalAgreementConditions.Update(item);
                }
                else
                {
                    // record not found
                    _context.RentalAgreementConditions.Add(item);
                }

                // save the changes
                _context.SaveChanges();

                return(new ObjectResult(new HetsResponse(item)));
            }

            // no record to insert
            return(new ObjectResult(new HetsResponse("HETS-04", ErrorViewModel.GetDescription("HETS-04", _configuration))));
        }
コード例 #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="item"></param>
        /// <response code="201">Project created</response>
        public virtual IActionResult RentalagreementconditionsPostAsync(RentalAgreementCondition item)
        {
            if (item != null)
            {
                AdjustRecord(item);

                var exists = _context.RentalAgreementConditions.Any(a => a.Id == item.Id);
                if (exists)
                {
                    _context.RentalAgreementConditions.Update(item);
                }
                else
                {
                    // record not found
                    _context.RentalAgreementConditions.Add(item);
                }
                // Save the changes
                _context.SaveChanges();
                return(new ObjectResult(item));
            }
            else
            {
                return(new StatusCodeResult(400));
            }
        }
コード例 #4
0
        /// <summary>
        /// Get rental agreement condition by id
        /// </summary>
        /// <param name="id">id of Project to fetch</param>
        /// <response code="200">OK</response>
        /// <response code="404">Project not found</response>
        public virtual IActionResult RentalagreementconditionsIdGetAsync(int id)
        {
            bool exists = _context.RentalAgreementConditions.Any(a => a.Id == id);

            if (exists)
            {
                RentalAgreementCondition result = _context.RentalAgreementConditions
                                                  .Include(x => x.RentalAgreement)
                                                  .First(a => a.Id == id);

                return(new ObjectResult(new HetsResponse(result)));
            }

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
コード例 #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">id of Project to fetch</param>
        /// <param name="item"></param>
        /// <response code="200">OK</response>
        /// <response code="404">Project not found</response>
        public virtual IActionResult RentalagreementconditionsIdPutAsync(int id, RentalAgreementCondition item)
        {
            AdjustRecord(item);
            var exists = _context.RentalAgreementConditions.Any(a => a.Id == id);

            if (exists && id == item.Id)
            {
                _context.RentalAgreementConditions.Update(item);
                // Save the changes
                _context.SaveChanges();
                return(new ObjectResult(item));
            }
            else
            {
                // record not found
                return(new StatusCodeResult(404));
            }
        }
コード例 #6
0
        /// <summary>
        /// Update rental agreement condition
        /// </summary>
        /// <param name="id">id of Project to update</param>
        /// <param name="item"></param>
        /// <response code="200">OK</response>
        /// <response code="404">Project not found</response>
        public virtual IActionResult RentalagreementconditionsIdPutAsync(int id, RentalAgreementCondition item)
        {
            AdjustRecord(item);

            bool exists = _context.RentalAgreementConditions.Any(a => a.Id == id);

            if (exists && id == item.Id)
            {
                _context.RentalAgreementConditions.Update(item);

                // save the changes
                _context.SaveChanges();

                return(new ObjectResult(new HetsResponse(item)));
            }

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
コード例 #7
0
        /// <summary>
        /// Delete rental agreement conditions
        /// </summary>
        /// <param name="id">id of Project to delete</param>
        /// <response code="200">OK</response>
        /// <response code="404">Project not found</response>
        public virtual IActionResult RentalagreementconditionsIdDeletePostAsync(int id)
        {
            bool exists = _context.RentalAgreementConditions.Any(a => a.Id == id);

            if (exists)
            {
                RentalAgreementCondition item = _context.RentalAgreementConditions.First(a => a.Id == id);

                if (item != null)
                {
                    _context.RentalAgreementConditions.Remove(item);

                    // save the changes
                    _context.SaveChanges();
                }

                return(new ObjectResult(new HetsResponse(item)));
            }

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
コード例 #8
0
 public virtual IActionResult RentalagreementconditionsPost([FromBody] RentalAgreementCondition item)
 {
     return(this._service.RentalagreementconditionsPostAsync(item));
 }
コード例 #9
0
 public virtual IActionResult RentalagreementconditionsIdPut([FromRoute] int id, [FromBody] RentalAgreementCondition item)
 {
     return(this._service.RentalagreementconditionsIdPutAsync(id, item));
 }
コード例 #10
0
        /// <summary>
        /// Integration test
        /// </summary>
        public async Task TestBasic()
        {
            string initialName = "InitialName";
            string changedName = "ChangedName";
            // first test the POST.
            var request = new HttpRequestMessage(HttpMethod.Post, "/api/rentalagreementconditions");

            // create a new object.
            RentalAgreementCondition rentalAgreementCondition = new RentalAgreementCondition();

            rentalAgreementCondition.Comment = initialName;
            string jsonString = rentalAgreementCondition.ToJson();

            request.Content = new StringContent(jsonString, Encoding.UTF8, "application/json");

            var response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            // parse as JSON.
            jsonString = await response.Content.ReadAsStringAsync();

            rentalAgreementCondition = JsonConvert.DeserializeObject <RentalAgreementCondition>(jsonString);

            // get the id
            var id = rentalAgreementCondition.Id;

            // change the name
            rentalAgreementCondition.Comment = changedName;

            // now do an update.
            request         = new HttpRequestMessage(HttpMethod.Put, "/api/rentalagreementconditions/" + id);
            request.Content = new StringContent(rentalAgreementCondition.ToJson(), Encoding.UTF8, "application/json");
            response        = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            // do a get.
            request  = new HttpRequestMessage(HttpMethod.Get, "/api/rentalagreementconditions/" + id);
            response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            // parse as JSON.
            jsonString = await response.Content.ReadAsStringAsync();

            rentalAgreementCondition = JsonConvert.DeserializeObject <RentalAgreementCondition>(jsonString);

            // verify the change went through.
            Assert.Equal(rentalAgreementCondition.Comment, changedName);

            // do a delete.
            request  = new HttpRequestMessage(HttpMethod.Post, "/api/rentalagreementconditions/" + id + "/delete");
            response = await _client.SendAsync(request);

            response.EnsureSuccessStatusCode();

            // should get a 404 if we try a get now.
            request  = new HttpRequestMessage(HttpMethod.Get, "/api/rentalagreementconditions/" + id);
            response = await _client.SendAsync(request);

            Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
        }
コード例 #11
0
ファイル: RentalAgreementService.cs プロジェクト: rstens/hets
        /// <summary>
        /// Update or create a condition records associated with a rental agreement
        /// </summary>
        /// <remarks>Update a Rental Agreement&#39;s Condition Record</remarks>
        /// <param name="id">id of Rental Agreement to update Condition Records for</param>
        /// <param name="item">Rental Agreement Condition Record</param>
        /// <response code="200">OK</response>
        public virtual IActionResult RentalAgreementsIdRentalAgreementConditionsPostAsync(int id, RentalAgreementCondition item)
        {
            bool exists = _context.RentalAgreements.Any(a => a.Id == id);

            if (exists && item != null)
            {
                RentalAgreement agreement = _context.RentalAgreements
                                            .Include(x => x.RentalAgreementConditions)
                                            .First(x => x.Id == id);

                // ******************************************************************
                // add or update condition records
                // ******************************************************************
                if (item.Id > 0)
                {
                    int condIndex = agreement.RentalAgreementConditions.FindIndex(a => a.Id == item.Id);

                    if (condIndex < 0)
                    {
                        // record not found
                        return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
                    }

                    agreement.RentalAgreementConditions[condIndex].Comment       = item.Comment;
                    agreement.RentalAgreementConditions[condIndex].ConditionName = item.ConditionName;
                }
                else // add condition records
                {
                    agreement.RentalAgreementConditions.Add(item);
                }

                _context.SaveChanges();

                // *************************************************************
                // return updated rental agreement condition records
                // *************************************************************
                List <RentalAgreementCondition> condRecords = new List <RentalAgreementCondition>();

                condRecords.AddRange(agreement.RentalAgreementConditions);

                return(new ObjectResult(new HetsResponse(condRecords)));
            }

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
コード例 #12
0
 public virtual IActionResult RentalagreementsIdRentalAgreementConditionsPost([FromRoute] int id, [FromBody] RentalAgreementCondition item)
 {
     return(_service.RentalAgreementsIdRentalAgreementConditionsPostAsync(id, item));
 }
コード例 #13
0
 /// <summary>
 /// Setup the test.
 /// </summary>
 public RentalAgreementConditionModelTests()
 {
     instance = new RentalAgreementCondition();
 }
コード例 #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="id">id of RentalAgreementCondition to fetch</param>
        /// <param name="item"></param>
        /// <response code="200">OK</response>
        /// <response code="404">RentalAgreementCondition not found</response>
        public virtual IActionResult RentalagreementconditionsIdPutAsync(int id, RentalAgreementCondition item)
        {
            var result = "";

            return(new ObjectResult(result));
        }