Beispiel #1
0
        public virtual IActionResult BatchReportIdDownloadGet([FromRoute] int id)
        {
            bool exists = _context.HetBatchReport.Any(a => a.ReportId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            HetBatchReport report = _context.HetBatchReport.AsNoTracking().First(a => a.ReportId == id);

            // report name
            string reportName = report.ReportName + ".pdf";

            // get binary
            byte[] reportBinary = FileUtility.FileToByteArray(report.ReportLink);

            // return content
            FileContentResult result = new FileContentResult(reportBinary, "application/pdf")
            {
                FileDownloadName = reportName
            };

            Response.Headers.Add("Content-Disposition", "inline; filename=" + reportName);

            return(result);
        }
Beispiel #2
0
        public virtual IActionResult ContactsIdDeletePost([FromRoute] int id)
        {
            bool exists = _context.HetContact.Any(a => a.ContactId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            HetContact item = _context.HetContact.First(a => a.ContactId == id);

            // check if this is a project - and if this is a "primary contact"
            if (item.ProjectId != null && item.ProjectId > 0)
            {
                int projectId = (int)item.ProjectId;

                HetProject project = _context.HetProject
                                     .FirstOrDefault(x => x.ProjectId == projectId);

                if (project != null && project.PrimaryContactId == id)
                {
                    project.PrimaryContactId = null;
                    _context.HetProject.Update(project);
                }
            }

            _context.HetContact.Remove(item);

            // save the changes
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(item)));
        }
Beispiel #3
0
        /// <summary>
        /// Get users associated with a group
        /// </summary>
        /// <remarks>Used to get users in a given Group</remarks>
        /// <param name="id">id of Group to fetch Users for</param>
        /// <response code="200">OK</response>
        public IActionResult GroupsIdUsersGetAsync(int id)
        {
            bool exists = _context.Groups.Any(a => a.Id == id);

            if (exists)
            {
                List <UserViewModel> result = new List <UserViewModel>();

                IQueryable <GroupMembership> data = _context.GroupMemberships
                                                    .Include("User")
                                                    .Include("Group")
                                                    .Where(x => x.Group.Id == id);

                // extract the users
                foreach (GroupMembership item in data)
                {
                    result.Add(item.User.ToViewModel());
                }

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

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
        public virtual IActionResult UserDistrictsIdSwitchPost([FromRoute] int id)
        {
            bool exists = _context.HetUserDistrict.Any(a => a.UserDistrictId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get record
            HetUserDistrict userDistrict = _context.HetUserDistrict.First(a => a.UserDistrictId == id);

            string userId = UserAccountHelper.GetUserId(_httpContext);

            HetUser user = _context.HetUser.First(a => a.SmUserId == userId);

            user.DistrictId = userDistrict.DistrictId;

            _context.SaveChanges();

            // create new district switch cookie
            _httpContext.Response.Cookies.Append(
                "HETSDistrict",
                userDistrict.DistrictId.ToString(),
                new CookieOptions
            {
                Path     = "/",
                SameSite = SameSiteMode.None
            }
                );

            return(new ObjectResult(new HetsResponse(user)));
        }
Beispiel #5
0
        public virtual IActionResult RolesIdPut([FromRoute] int id, [FromBody] HetRole item)
        {
            bool exists = _context.HetRole.Any(x => x.RoleId == id);

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

            // get record
            HetRole role = _context.HetRole.First(x => x.RoleId == id);

            role.ConcurrencyControlNumber = item.ConcurrencyControlNumber;
            role.Name        = item.Name;
            role.Description = item.Description;

            // save changes
            _context.SaveChanges();

            // get updated role
            role = _context.HetRole.AsNoTracking()
                   .First(x => x.RoleId == id);

            // return role permissions
            return(new ObjectResult(new HetsResponse(role)));
        }
Beispiel #6
0
        public virtual IActionResult EquipmentAttachmentsPost([FromBody] HetEquipmentAttachment item)
        {
            // not found
            if (item == null)
            {
                return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // create record
            HetEquipmentAttachment equipmentAttachment = new HetEquipmentAttachment
            {
                ConcurrencyControlNumber = item.ConcurrencyControlNumber,
                Description = item.TypeName,
                TypeName    = item.TypeName,
                EquipmentId = item.Equipment.EquipmentId
            };

            // save the changes
            _context.HetEquipmentAttachment.Add(equipmentAttachment);
            _context.SaveChanges();

            // get the id (in the case of new records)
            int id = equipmentAttachment.EquipmentAttachmentId;

            // return the updated condition type record
            HetEquipmentAttachment updEquipmentAttachment = _context.HetEquipmentAttachment.AsNoTracking()
                                                            .Include(x => x.Equipment)
                                                            .FirstOrDefault(a => a.EquipmentAttachmentId == id);

            return(new ObjectResult(new HetsResponse(updEquipmentAttachment)));
        }
Beispiel #7
0
        /// <summary>
        /// Update a contact associated with a project
        /// </summary>
        /// <remarks>Updates a Contact associated with a Project</remarks>
        /// <param name="id">id of Project to add Contact to</param>
        /// <param name="item">Project contact</param>
        /// <param name="primary"></param>
        /// <response code="200">OK</response>
        public virtual IActionResult ProjectsIdContactsPostAsync(int id, Contact item, bool primary)
        {
            bool exists = _context.Projects.Any(a => a.Id == id);

            if (exists && item != null)
            {
                Project project = _context.Projects
                                  .Include(x => x.District.Region)
                                  .Include(x => x.Notes)
                                  .Include(x => x.Attachments)
                                  .Include(x => x.History)
                                  .Include(x => x.Contacts)
                                  .First(x => x.Id == id);

                // adjust the incoming list
                item.Id = 0;

                _context.Contacts.Add(item);
                project.Contacts.Add(item);

                if (primary)
                {
                    project.PrimaryContact = item;
                }

                _context.Projects.Update(project);
                _context.SaveChanges();

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

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
Beispiel #8
0
        /// <summary>
        /// Release (terminate) a rental agreement
        /// </summary>
        /// /// <param name="id">Id of Rental Agreement to release</param>
        /// <response code="200">Rental Agreement released</response>
        public virtual IActionResult RentalagreementsIdReleasePostAsync(int id)
        {
            bool exists = _context.RentalAgreements.Any(a => a.Id == id);

            if (exists)
            {
                RentalAgreement rentalAgreement = _context.RentalAgreements.FirstOrDefault(a => a.Id == id);

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

                // release (terminate) rental agreement
                rentalAgreement.Status = "Complete";

                _context.RentalAgreements.Update(rentalAgreement);

                // save the changes
                _context.SaveChanges();

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

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
Beispiel #9
0
        /// <summary>
        /// Delete user district
        /// </summary>
        /// <param name="id">id of user district to delete</param>
        /// <response code="200">OK</response>
        public virtual IActionResult UserDistrictsIdDeletePostAsync(int id)
        {
            bool exists = _context.UserDistricts.Any(a => a.Id == id);

            if (exists)
            {
                UserDistrict item = _context.UserDistricts
                                    .Include(x => x.User)
                                    .First(a => a.Id == id);

                int userId = item.User.Id;

                // remove record
                _context.UserDistricts.Remove(item);

                // save the changes
                _context.SaveChanges();

                // return the updated user district records
                List <UserDistrict> userDistricts = _context.UserDistricts
                                                    .Include(x => x.User)
                                                    .Include(x => x.District)
                                                    .Where(x => x.User.Id == userId)
                                                    .ToList();

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

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
Beispiel #10
0
        /// <summary>
        /// Update owner
        /// </summary>
        /// <param name="id">id of Owner to update</param>
        /// <param name="item"></param>
        /// <response code="200">OK</response>
        /// <response code="404">Owner not found</response>
        public virtual IActionResult OwnersIdPutAsync(int id, Owner item)
        {
            if (item != null)
            {
                AdjustRecord(item);

                // we specifically do not want to change contacts from this service
                item.Contacts = GetOwnerContacts(id);

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

                if (exists && id == item.Id)
                {
                    _context.Owners.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))));
            }

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
Beispiel #11
0
        /// <summary>
        /// Get rental agreement 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 RentalagreementsIdGetAsync(int id)
        {
            bool exists = _context.RentalAgreements.Any(a => a.Id == id);

            if (exists)
            {
                RentalAgreement result = _context.RentalAgreements.AsNoTracking()
                                         .Include(x => x.Equipment)
                                         .ThenInclude(y => y.Owner)
                                         .Include(x => x.Equipment)
                                         .ThenInclude(y => y.DistrictEquipmentType)
                                         .ThenInclude(d => d.EquipmentType)
                                         .Include(x => x.Equipment)
                                         .ThenInclude(y => y.EquipmentAttachments)
                                         .Include(x => x.Equipment)
                                         .ThenInclude(y => y.LocalArea.ServiceArea.District.Region)
                                         .Include(x => x.Project)
                                         .ThenInclude(p => p.District.Region)
                                         .Include(x => x.RentalAgreementConditions)
                                         .Include(x => x.RentalAgreementRates)
                                         .Include(x => x.TimeRecords)
                                         .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))));
        }
Beispiel #12
0
        /// <summary>
        /// Get owner by id
        /// </summary>
        /// <param name="id">id of Owner to fetch</param>
        /// <response code="200">OK</response>
        /// <response code="404">Owner not found</response>
        public virtual IActionResult OwnersIdGetAsync(int id)
        {
            bool exists = _context.Owners.Any(a => a.Id == id);

            if (exists)
            {
                Owner result = _context.Owners
                               .Include(x => x.LocalArea.ServiceArea.District.Region)
                               .Include(x => x.EquipmentList).ThenInclude(y => y.LocalArea.ServiceArea.District.Region)
                               .Include(x => x.EquipmentList).ThenInclude(y => y.DistrictEquipmentType)
                               .Include(x => x.EquipmentList).ThenInclude(y => y.DumpTruck)
                               .Include(x => x.EquipmentList).ThenInclude(y => y.Owner)
                               .Include(x => x.EquipmentList).ThenInclude(y => y.EquipmentAttachments)
                               .Include(x => x.EquipmentList).ThenInclude(y => y.Notes)
                               .Include(x => x.EquipmentList).ThenInclude(y => y.Attachments)
                               .Include(x => x.EquipmentList).ThenInclude(y => y.History)
                               .Include(x => x.Notes)
                               .Include(x => x.Attachments)
                               .Include(x => x.History)
                               .Include(x => x.Contacts)
                               .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))));
        }
Beispiel #13
0
        /// <summary>
        /// Update contact associated with an owner
        /// </summary>
        /// <remarks>Replaces an Owner&#39;s Contacts</remarks>
        /// <param name="id">id of Owner to replace Contacts for</param>
        /// <param name="item">Replacement Owner contacts.</param>
        /// <response code="200">OK</response>
        public virtual IActionResult OwnersIdContactsPostAsync(int id, Contact item)
        {
            bool exists = _context.Owners.Any(a => a.Id == id);

            if (exists && item != null)
            {
                Owner owner = _context.Owners
                              .Include(x => x.LocalArea.ServiceArea.District.Region)
                              .Include(x => x.EquipmentList)
                              .ThenInclude(y => y.DistrictEquipmentType)
                              .Include(x => x.Notes)
                              .Include(x => x.Attachments)
                              .Include(x => x.History)
                              .Include(x => x.Contacts)
                              .First(x => x.Id == id);

                // adjust the incoming list.
                item.Id = 0;

                _context.Contacts.Add(item);
                owner.Contacts.Add(item);
                _context.Owners.Update(owner);
                _context.SaveChanges();

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

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
Beispiel #14
0
        public virtual IActionResult BatchReportIdDeletePost([FromRoute] int id)
        {
            bool exists = _context.HetBatchReport.Any(a => a.ReportId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            HetBatchReport report = _context.HetBatchReport.First(a => a.ReportId == id);

            if (report != null)
            {
                _context.HetBatchReport.Remove(report);

                // delete file
                FileUtility.DeleteFile(report.ReportLink);

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

            return(new ObjectResult(new HetsResponse(report)));
        }
        public virtual IActionResult RentalAgreementRatesIdPut([FromRoute] int id, [FromBody] HetRentalAgreementRate item)
        {
            bool exists = _context.HetRentalAgreementRate.Any(a => a.RentalAgreementRateId == id);

            // not found
            if (!exists || id != item.RentalAgreementRateId)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // set the rate period type id
            int ratePeriodTypeId = StatusHelper.GetRatePeriodId(item.RatePeriod, _context) ?? throw new DataException("Rate Period Id cannot be null");

            // get record
            HetRentalAgreementRate rate = _context.HetRentalAgreementRate.First(a => a.RentalAgreementRateId == id);

            rate.ConcurrencyControlNumber = item.ConcurrencyControlNumber;

            rate.Comment           = item.Comment;
            rate.ComponentName     = item.ComponentName;
            rate.IsIncludedInTotal = item.IsIncludedInTotal;
            rate.Rate             = item.Rate;
            rate.RatePeriodTypeId = ratePeriodTypeId;
            rate.Active           = true;
            rate.Overtime         = false;
            rate.Set = item.Set;

            // save the changes
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(rate)));
        }
Beispiel #16
0
        /// <summary>
        /// Switch user district
        /// </summary>
        /// <param name="id">id of user district to switch to</param>
        /// <response code="200">OK</response>
        public virtual IActionResult UserDistrictsIdSwitchPostAsync(int id)
        {
            bool exists = _context.UserDistricts.Any(a => a.Id == id);

            if (exists)
            {
                UserDistrict userDistrict = _context.UserDistricts.First(a => a.Id == id);

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

                int?userId = GetCurrentUserId();

                User user = _context.Users.First(a => a.Id == userId);
                user.DistrictId = userDistrict.DistrictId;

                _context.SaveChanges();

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

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
Beispiel #17
0
        public virtual IActionResult ProvincialRatesIdPut([FromRoute] int id, [FromBody] HetProvincialRateType item)
        {
            bool exists = _context.HetProvincialRateType.Any(a => a.RateType == item.RateType);

            // not found
            if (!exists || id != item.Id)
            {
                return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get record
            HetProvincialRateType rate = _context.HetProvincialRateType.First(a => a.RateType == item.RateType);

            rate.ConcurrencyControlNumber = item.ConcurrencyControlNumber;
            rate.Description       = item.Description;
            rate.Rate              = item.Rate;
            rate.Active            = item.Active;
            rate.IsIncludedInTotal = item.IsIncludedInTotal;
            rate.IsInTotalEditable = item.IsInTotalEditable;
            rate.IsRateEditable    = item.IsRateEditable;
            rate.IsPercentRate     = item.IsPercentRate;
            rate.PeriodType        = item.PeriodType;

            // save the changes
            _context.SaveChanges();

            // get the updated record and return
            rate    = _context.HetProvincialRateType.First(a => a.RateType == item.RateType);
            rate.Id = id;

            return(new ObjectResult(new HetsResponse(rate)));
        }
        public virtual IActionResult UsersCurrentFavouritesIdDeletePost([FromRoute] int id)
        {
            // get the current user id
            string userId = _context.SmUserId;

            // not found
            if (userId == null)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            bool exists = _context.HetUserFavourite
                          .Where(x => x.User.SmUserId == userId)
                          .Any(a => a.UserFavouriteId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // delete favourite
            HetUserFavourite item = _context.HetUserFavourite.First(a => a.UserFavouriteId == id);

            _context.HetUserFavourite.Remove(item);

            // save the changes
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(item)));
        }
Beispiel #19
0
        /// <summary>
        /// Get project 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 ProjectsIdGetAsync(int id)
        {
            bool exists = _context.Projects.Any(a => a.Id == id);

            if (exists)
            {
                Project result = _context.Projects
                                 .Include(x => x.Attachments)
                                 .Include(x => x.Contacts)
                                 .Include(x => x.History)
                                 .Include(x => x.District.Region)
                                 .Include(x => x.Notes)
                                 .Include(x => x.PrimaryContact)
                                 .Include(x => x.RentalRequests)
                                 .ThenInclude(e => e.DistrictEquipmentType)
                                 .ThenInclude(d => d.EquipmentType)
                                 .Include(x => x.RentalAgreements)
                                 .ThenInclude(e => e.Equipment)
                                 .ThenInclude(d => d.DistrictEquipmentType)
                                 .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))));
        }
Beispiel #20
0
        public virtual IActionResult UsersPost([FromBody] HetUser item)
        {
            // not found
            if (item == null)
            {
                return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            HetUser user = new HetUser
            {
                Active        = item.Active,
                Email         = item.Email,
                GivenName     = item.GivenName,
                Surname       = item.Surname,
                SmUserId      = item.SmUserId,
                DistrictId    = item.District.DistrictId,
                AgreementCity = item.AgreementCity
            };

            HetUserDistrict newUserDistrict = new HetUserDistrict
            {
                DistrictId = item.District.DistrictId,
                IsPrimary  = true
            };

            user.HetUserDistrict.Add(newUserDistrict);

            _context.HetUser.Add(user);
            _context.SaveChanges();

            int id = user.UserId;

            // get updated user record and return to UI
            return(new ObjectResult(new HetsResponse(UserHelper.GetRecord(id, _context))));
        }
Beispiel #21
0
        /// <summary>
        /// Get project history
        /// </summary>
        /// <remarks>Returns History for a particular Project</remarks>
        /// <param name="id">id of Project to fetch History for</param>
        /// <param name="offset"></param>
        /// <param name="limit"></param>
        /// <response code="200">OK</response>
        public virtual IActionResult ProjectsIdHistoryGetAsync(int id, int?offset, int?limit)
        {
            bool exists = _context.Projects.Any(a => a.Id == id);

            if (exists)
            {
                Project project = _context.Projects
                                  .Include(x => x.History)
                                  .First(a => a.Id == id);

                List <History> data = project.History.OrderByDescending(y => y.LastUpdateTimestamp).ToList();

                if (offset == null)
                {
                    offset = 0;
                }

                if (limit == null)
                {
                    limit = data.Count - offset;
                }

                List <HistoryViewModel> result = new List <HistoryViewModel>();

                for (int i = (int)offset; i < data.Count && i < offset + limit; i++)
                {
                    result.Add(data[i].ToViewModel(id));
                }

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

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
Beispiel #22
0
        public virtual IActionResult UsersIdPermissionsGet([FromRoute] int id)
        {
            bool exists = _context.HetUser.Any(x => x.UserId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get record
            HetUser user = UserHelper.GetRecord(id, _context);

            List <HetPermission> permissions = new List <HetPermission>();

            foreach (HetUserRole item in user.HetUserRole)
            {
                if (item.Role?.HetRolePermission != null)
                {
                    foreach (HetRolePermission permission in item.Role.HetRolePermission)
                    {
                        permissions.Add(permission.Permission);
                    }
                }
            }

            return(new ObjectResult(new HetsResponse(permissions)));
        }
        public virtual IActionResult UserDistrictsIdDeletePost([FromRoute] int id)
        {
            bool exists = _context.HetUserDistrict.Any(a => a.UserDistrictId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get record
            HetUserDistrict item = _context.HetUserDistrict
                                   .Include(x => x.User)
                                   .First(a => a.UserDistrictId == id);

            int userId = item.User.UserId;

            // remove record
            _context.HetUserDistrict.Remove(item);
            _context.SaveChanges();

            // return the updated user district records
            List <HetUserDistrict> result = _context.HetUserDistrict.AsNoTracking()
                                            .Include(x => x.User)
                                            .Include(x => x.District)
                                            .Where(x => x.User.UserId == userId)
                                            .ToList();

            return(new ObjectResult(new HetsResponse(result)));
        }
Beispiel #24
0
        public virtual IActionResult UsersIdDeletePost([FromRoute] int id)
        {
            bool exists = _context.HetUser.Any(x => x.UserId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // get record
            HetUser user = _context.HetUser.AsNoTracking()
                           .Include(x => x.HetUserRole)
                           .Include(x => x.HetUserDistrict)
                           .First(x => x.UserId == id);

            // delete user roles
            foreach (HetUserRole item in user.HetUserRole)
            {
                _context.HetUserRole.Remove(item);
            }

            // delete user districts
            foreach (HetUserDistrict item in user.HetUserDistrict)
            {
                _context.HetUserDistrict.Remove(item);
            }

            // delete user
            _context.HetUser.Remove(user);
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(user)));
        }
Beispiel #25
0
        public virtual IActionResult RolesIdDeletePost([FromRoute] int id)
        {
            bool exists = _context.HetRole.Any(x => x.RoleId == id);

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

            // get record
            HetRole role = _context.HetRole.First(x => x.RoleId == id);

            // remove associated role permission records
            List <HetRolePermission> itemsToRemove = _context.HetRolePermission
                                                     .Where(x => x.Role.RoleId == role.RoleId)
                                                     .ToList();

            foreach (HetRolePermission item in itemsToRemove)
            {
                _context.HetRolePermission.Remove(item);
            }

            // remove role and save
            _context.HetRole.Remove(role);
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(role)));
        }
Beispiel #26
0
        public virtual IActionResult DistrictFiscalYearsGet([FromRoute] int id)
        {
            bool exists = _context.HetDistrict.Any(a => a.DistrictId == id);

            // not found
            if (!exists)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            HetDistrictStatus status = _context.HetDistrictStatus
                                       .AsNoTracking()
                                       .FirstOrDefault(x => x.DistrictId == id);

            if (status == null)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            List <string> fiscalYears = new List <string>();

            string current = $"{status.CurrentFiscalYear.ToString()}/{(status.CurrentFiscalYear + 1).ToString()}";
            string next    = $"{status.NextFiscalYear.ToString()}/{(status.NextFiscalYear + 1).ToString()}";

            fiscalYears.Add(current);
            fiscalYears.Add(next);

            return(new ObjectResult(new HetsResponse(fiscalYears)));
        }
Beispiel #27
0
        /// <summary>
        /// Create equipment attachments
        /// </summary>
        /// <param name="item"></param>
        /// <response code="200">Equipment Attachment created</response>
        public virtual IActionResult EquipmentAttachmentsPostAsync(EquipmentAttachment item)
        {
            if (item != null)
            {
                AdjustRecord(item);

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

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

                // Save the changes
                _context.SaveChanges();

                int itemId = item.Id;

                EquipmentAttachment result = _context.EquipmentAttachments
                                             .Include(x => x.Equipment)
                                             .First(a => a.Id == itemId);

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

            // record not found
            return(new ObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
        }
        public virtual IActionResult EquipmentAttachmentsBulkPost([FromBody] HetEquipmentAttachment[] items)
        {
            // not found
            if (items == null || items.Length < 1)
            {
                return(new NotFoundObjectResult(new HetsResponse("HETS-01", ErrorViewModel.GetDescription("HETS-01", _configuration))));
            }

            // process each attachment records
            foreach (HetEquipmentAttachment item in items)
            {
                HetEquipmentAttachment equipmentAttachment = new HetEquipmentAttachment
                {
                    ConcurrencyControlNumber = item.ConcurrencyControlNumber,
                    Description = item.TypeName,
                    TypeName    = item.TypeName,
                    EquipmentId = item.Equipment.EquipmentId
                };

                // save the changes
                _context.HetEquipmentAttachment.Add(equipmentAttachment);
            }

            _context.SaveChanges();

            // return all equipment attachments
            int id = items[0].Equipment.EquipmentId;

            List <HetEquipmentAttachment> attachments = _context.HetEquipmentAttachment.AsNoTracking()
                                                        .Where(x => x.EquipmentId == id).ToList();

            return(new ObjectResult(new HetsResponse(attachments)));
        }
        /// <summary>
        /// Create rental agreement rate
        /// </summary>
        /// <param name="item"></param>
        /// <response code="201">Project created</response>
        public virtual IActionResult RentalagreementratesPostAsync(RentalAgreementRate item)
        {
            if (item != null)
            {
                AdjustRecord(item);

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

                if (exists)
                {
                    _context.RentalAgreementRates.Update(item);
                }
                else
                {
                    // record not found
                    _context.RentalAgreementRates.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))));
        }
Beispiel #30
0
        /// <summary>
        /// Delete rental request
        /// </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 RentalrequestsIdDeletePostAsync(int id)
        {
            RentalRequest item = _context.RentalRequests
                                 .Include(x => x.RentalRequestRotationList)
                                 .FirstOrDefault(a => a.Id == id);

            if (item != null)
            {
                // remove the rotation list if it exists
                if (item.RentalRequestRotationList != null)
                {
                    foreach (RentalRequestRotationList rentalRequestRotationList in item.RentalRequestRotationList)
                    {
                        _context.RentalRequestRotationLists.Remove(rentalRequestRotationList);
                    }
                }

                _context.RentalRequests.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))));
        }