Exemplo n.º 1
0
        /// <summary>
        /// Printed rental agreement view model
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public static RentalRequestViewModel ToRentalRequestViewModel(this RentalRequest model)
        {
            var dto = new RentalRequestViewModel();

            if (model != null)
            {
                dto.Id                        = model.Id;
                dto.Project                   = model.Project;
                dto.LocalArea                 = model.LocalArea;
                dto.Status                    = model.Status;
                dto.DistrictEquipmentType     = model.DistrictEquipmentType;
                dto.EquipmentCount            = model.EquipmentCount;
                dto.ExpectedHours             = model.ExpectedHours;
                dto.ExpectedStartDate         = model.ExpectedStartDate;
                dto.ExpectedEndDate           = model.ExpectedEndDate;
                dto.FirstOnRotationList       = model.FirstOnRotationList;
                dto.Notes                     = model.Notes;
                dto.Attachments               = model.Attachments;
                dto.History                   = model.History;
                dto.RentalRequestAttachments  = model.RentalRequestAttachments;
                dto.RentalRequestRotationList = model.RentalRequestRotationList;

                // calculate the Yes Count based on the RentalRequestList
                dto.CalculateYesCount();
            }

            return(dto);
        }
Exemplo n.º 2
0
        public IHttpActionResult GetRentalRequest(int id)
        {
            RentalRequestDto rentalRequest = _rentalRequestService.Find(id);

            if (rentalRequest == null)
            {
                return(NotFound());
            }

            RentalRequestViewModel view = _mapper.Map <RentalRequestViewModel>(rentalRequest);

            return(Ok(view));
        }
Exemplo n.º 3
0
        /// <summary>
        /// Printed rental agreement view model
        /// </summary>
        /// <param name="model"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public static RentalRequestViewModel ToRentalRequestViewModel(this RentalRequest model, DbAppContext context)
        {
            var dto = new RentalRequestViewModel();

            if (model != null)
            {
                dto.Id                        = model.Id;
                dto.Project                   = model.Project;
                dto.LocalArea                 = model.LocalArea;
                dto.Status                    = model.Status;
                dto.DistrictEquipmentType     = model.DistrictEquipmentType;
                dto.EquipmentCount            = model.EquipmentCount;
                dto.ExpectedHours             = model.ExpectedHours;
                dto.ExpectedStartDate         = model.ExpectedStartDate;
                dto.ExpectedEndDate           = model.ExpectedEndDate;
                dto.FirstOnRotationList       = model.FirstOnRotationList;
                dto.Notes                     = model.Notes;
                dto.Attachments               = model.Attachments;
                dto.History                   = model.History;
                dto.RentalRequestAttachments  = model.RentalRequestAttachments;
                dto.RentalRequestRotationList = model.RentalRequestRotationList;

                // calculate the Yes Count based on the RentalRequestList
                dto.CalculateYesCount();

                // calculate YTD hours for the equipment records
                if (dto.RentalRequestRotationList != null)
                {
                    foreach (RentalRequestRotationList rotationList in dto.RentalRequestRotationList)
                    {
                        if (rotationList.Equipment != null)
                        {
                            rotationList.Equipment.HoursYtd =
                                rotationList.Equipment.GetYtdServiceHours(context);
                        }
                    }
                }
            }

            return(dto);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get rental request rotation list by rental request id
        /// </summary>
        /// <param name="id">id of Rental Request to fetch</param>
        /// <response code="200">OK</response>
        /// <response code="404">Project not found</response>
        public virtual IActionResult RentalrequestsIdRotationListGetAsync(int id)
        {
            bool exists = _context.RentalRequests.Any(a => a.Id == id);

            if (exists)
            {
                // check that we have a rotation list
                RentalRequest result = _context.RentalRequests
                                       .Include(x => x.DistrictEquipmentType)
                                       .ThenInclude(y => y.EquipmentType)
                                       .Include(x => x.FirstOnRotationList)
                                       .Include(x => x.RentalRequestAttachments)
                                       .Include(x => x.RentalRequestRotationList)
                                       .ThenInclude(y => y.Equipment)
                                       .ThenInclude(r => r.EquipmentAttachments)
                                       .Include(x => x.RentalRequestRotationList)
                                       .ThenInclude(y => y.Equipment)
                                       .ThenInclude(e => e.Owner)
                                       .ThenInclude(c => c.PrimaryContact)
                                       .First(a => a.Id == id);

                // resort list using: LocalArea / District Equipment Type and SenioritySortOrder (desc)
                result.RentalRequestRotationList =
                    result.RentalRequestRotationList.OrderBy(e => e.RotationListSortOrder).ToList();

                // return the number of blocks in this list
                RentalRequestViewModel rentalRequest = result.ToRentalRequestViewModel();
                rentalRequest.NumberOfBlocks = GetNumberOfBlocks(result) + 1;

                // return view model
                return(new ObjectResult(new HetsResponse(rentalRequest)));
            }

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