Esempio n. 1
0
        public virtual IActionResult BceidOwnersGet()
        {
            // get business
            string businessGuid = UserAccountHelper.GetBusinessGuid(_httpContext, _env);

            HetBusiness business = _context.HetBusiness.AsNoTracking()
                                   .FirstOrDefault(x => x.BceidBusinessGuid.ToLower().Trim() == businessGuid.ToLower().Trim());

            if (business == null)
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }

            // check access
            if (!CanAccessBusiness(business.BusinessId))
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }

            // get business
            HetBusiness businessDetail = _context.HetBusiness.AsNoTracking()
                                         .Include(x => x.HetOwner)
                                         .ThenInclude(y => y.PrimaryContact)
                                         .Include(x => x.HetOwner)
                                         .ThenInclude(y => y.Business)
                                         .Include(x => x.HetOwner)
                                         .ThenInclude(y => y.LocalArea.ServiceArea.District)
                                         .FirstOrDefault(a => a.BusinessId == business.BusinessId);

            return(new ObjectResult(new HetsResponse(businessDetail)));
        }
Esempio n. 2
0
        public virtual IActionResult BceidOwnerIdGet([FromRoute] int id)
        {
            // get business
            string businessGuid = UserAccountHelper.GetBusinessGuid(_httpContext, _env);

            HetBusiness business = _context.HetBusiness.AsNoTracking()
                                   .FirstOrDefault(x => x.BceidBusinessGuid.ToLower().Trim() == businessGuid.ToLower().Trim());

            if (business == null)
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }

            // check access
            if (!CanAccessOwner(business.BusinessId, id))
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }

            return(new ObjectResult(new HetsResponse(OwnerHelper.GetRecord(id, _context, _configuration))));
        }
Esempio n. 3
0
        public virtual IActionResult BceidOwnerEquipmentGet([FromRoute] int id)
        {
            // get business
            string businessGuid = UserAccountHelper.GetBusinessGuid(_httpContext, _env);

            HetBusiness business = _context.HetBusiness.AsNoTracking()
                                   .FirstOrDefault(x => x.BceidBusinessGuid.ToLower().Trim() == businessGuid.ToLower().Trim());

            if (business == null)
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }

            // check access
            if (!CanAccessOwner(business.BusinessId, id))
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }

            // retrieve the data and return
            HetOwner owner = _context.HetOwner.AsNoTracking()
                             .Include(x => x.HetEquipment)
                             .ThenInclude(x => x.LocalArea.ServiceArea.District.Region)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(x => x.DistrictEquipmentType)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(x => x.Owner)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(x => x.HetEquipmentAttachment)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(x => x.HetNote)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(x => x.HetDigitalFile)
                             .Include(x => x.HetEquipment)
                             .ThenInclude(x => x.HetHistory)
                             .First(a => a.OwnerId == id);

            return(new ObjectResult(new HetsResponse(owner.HetEquipment)));
        }
Esempio n. 4
0
        public virtual IActionResult BceidBusinessGet()
        {
            string businessGuid = UserAccountHelper.GetBusinessGuid(_httpContext, _env);

            if (businessGuid == null)
            {
                return(new NotFoundObjectResult(new HetsResponse("")));
            }

            HetBusiness business = _context.HetBusiness.AsNoTracking()
                                   .Include(x => x.HetOwner)
                                   .ThenInclude(y => y.PrimaryContact)
                                   .Include(x => x.HetOwner)
                                   .ThenInclude(y => y.LocalArea)
                                   .ThenInclude(z => z.ServiceArea.District)
                                   .FirstOrDefault(x => x.BceidBusinessGuid.ToLower().Trim() == businessGuid.ToLower().Trim());

            if (business == null)
            {
                return(new NotFoundObjectResult(new HetsResponse("")));
            }

            return(new ObjectResult(new HetsResponse(business)));
        }
Esempio n. 5
0
        public virtual IActionResult BceidValidateOwner([FromQuery] string sharedKey, [FromQuery] string postalCode)
        {
            string businessGuid = UserAccountHelper.GetBusinessGuid(_httpContext, _env);

            if (string.IsNullOrEmpty(sharedKey))
            {
                // shared key not provided
                return(new BadRequestObjectResult(new HetsResponse("HETS-19", ErrorViewModel.GetDescription("HETS-19", _configuration))));
            }

            if (string.IsNullOrEmpty(postalCode))
            {
                // postal code not provided
                return(new BadRequestObjectResult(new HetsResponse("HETS-22", ErrorViewModel.GetDescription("HETS-22", _configuration))));
            }

            bool exists = _context.HetBusiness.Any(a => a.BceidBusinessGuid.ToLower().Trim() == businessGuid.ToLower().Trim());

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

            // get business
            HetBusiness business = _context.HetBusiness.AsNoTracking()
                                   .First(x => x.BceidBusinessGuid.ToLower().Trim() == businessGuid.ToLower().Trim());

            // find owner using shred key & postal code (exact match)
            HetOwner owner = _context.HetOwner
                             .Include(a => a.Business)
                             .FirstOrDefault(a => a.SharedKey.Equals(sharedKey) &&
                                             a.PostalCode.Replace(" ", "").ToLower().Equals(postalCode.Replace(" ", "").ToLower(), StringComparison.InvariantCultureIgnoreCase));

            // validate the key
            if (owner == null)
            {
                // shared key not found
                return(new BadRequestObjectResult(new HetsResponse("HETS-20", ErrorViewModel.GetDescription("HETS-20", _configuration))));
            }

            if (owner.BusinessId != null)
            {
                // shared key already used
                return(new BadRequestObjectResult(new HetsResponse("HETS-21", ErrorViewModel.GetDescription("HETS-21", _configuration))));
            }

            // update owner
            int ownerId = owner.OwnerId;

            owner.BusinessId = business.BusinessId;
            owner.SharedKey  = null;
            _context.SaveChanges();

            // get updated business record and return to the UI
            business = _context.HetBusiness.AsNoTracking()
                       .Include(x => x.HetOwner)
                       .ThenInclude(y => y.PrimaryContact)
                       .Include(x => x.HetOwner)
                       .ThenInclude(y => y.Business)
                       .Include(x => x.HetOwner)
                       .ThenInclude(y => y.LocalArea.ServiceArea.District)
                       .FirstOrDefault(a => a.BusinessId == business.BusinessId);

            // get updated owner record (linked owner) and return to the UI too
            if (business != null)
            {
                business.LinkedOwner = _context.HetOwner.AsNoTracking()
                                       .FirstOrDefault(x => x.OwnerId == ownerId);
            }

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