Beispiel #1
0
        public async Task <IActionResult> PutRequest(int id, Request request)
        {
            if (id != request.Id)
            {
                return(BadRequest());
            }

            _context.Entry(request).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!RequestExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #2
0
 public ActionResult Edit([Bind(Include = "NoticeId,NoticeDescription,NoticeDate")] Notice notice)
 {
     if (ModelState.IsValid)
     {
         db.Entry(notice).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(notice));
 }
Beispiel #3
0
        // Returns contacts for a specific owner.
        private List <Contact> GetOwnerContacts(int id)
        {
            List <Contact> result = null;
            Owner          owner  = _context.Owners
                                    .Include(x => x.Contacts)
                                    .FirstOrDefault(x => x.Id == id);

            if (owner != null)
            {
                result = owner.Contacts;
            }
            _context.Entry(owner).State = EntityState.Detached;

            return(result);
        }
        /// <summary>
        ///
        /// </summary>
        /// <remarks>Updates a region</remarks>
        /// <param name="id">id of Region to update</param>
        /// <param name="item"></param>
        /// <response code="200">OK</response>
        /// <response code="404">Region not found</response>

        public virtual IActionResult RegionsIdPutAsync(int id, Region item)
        {
            var exists = _context.Regions.Any(a => a.Id == id);

            if (exists && id == item.Id)
            {
                _context.Entry(item).State = EntityState.Modified;
                // save the changes
                _context.SaveChanges();
                return(new ObjectResult(item));
            }
            else
            {
                // record not found
                return(new StatusCodeResult(404));
            }
        }
Beispiel #5
0
        /// <summary>
        /// Update region
        /// </summary>
        /// <remarks>Updates a region</remarks>
        /// <param name="id">id of Region to update</param>
        /// <param name="item"></param>
        /// <response code="200">OK</response>
        /// <response code="404">Region not found</response>
        public virtual IActionResult RegionsIdPutAsync(int id, Region item)
        {
            bool exists = _context.Regions.Any(a => a.Id == id);

            if (exists && id == item.Id)
            {
                _context.Entry(item).State = EntityState.Modified;

                // 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))));
        }
Beispiel #6
0
        /// <summary>
        /// Recalculates seniority for an entire region
        /// </summary>
        /// <remarks>Used to calculate seniority for all database records</remarks>
        /// <response code="200">OK</response>
        public virtual IActionResult EquipmentRecalcSeniorityGetAsync(int region)
        {
            // check if the region is valid
            bool exists = _context.Regions.Any(a => a.Id == region);

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

            // get all local areas for this region
            List <LocalArea> localAreas = _context.Equipments
                                          .Include(x => x.LocalArea)
                                          .Where(x => x.LocalArea.ServiceArea.District.Region.Id == region)
                                          .Select(x => x.LocalArea)
                                          .Distinct()
                                          .ToList();

            // get all district equipment types for this region
            List <DistrictEquipmentType> equipmentTypes = _context.Equipments
                                                          .Include(x => x.DistrictEquipmentType)
                                                          .Where(x => x.LocalArea.ServiceArea.District.Region.Id == region)
                                                          .Select(x => x.DistrictEquipmentType)
                                                          .Distinct()
                                                          .ToList();

            foreach (DistrictEquipmentType equipment in equipmentTypes)
            {
                _context.Entry(equipment).Reference(x => x.EquipmentType).Load();
            }

            foreach (LocalArea localArea in localAreas)
            {
                foreach (DistrictEquipmentType districtEquipmentType in equipmentTypes)
                {
                    _context.CalculateSeniorityList(localArea.Id, districtEquipmentType.Id, districtEquipmentType.EquipmentType.Id, _configuration);
                }
            }

            return(new ObjectResult("Done Recalc"));
        }
        /// <summary>
        ///
        /// </summary>
        /// <remarks>Updates a rental request rotation list entry.  Side effect is the LocalAreaRotationList is also updated</remarks>
        /// <param name="id">id of RentalRequest to update</param>
        /// <param name="rentalRequestRotationListId">id of RentalRequestRotationList to update</param>
        /// <param name="item"></param>
        /// <response code="200">OK</response>
        /// <response code="404">RentalRequestRotationList not found</response>
        public virtual IActionResult RentalrequestsIdRentalrequestrotationlistRentalRequestRotationListIdPutAsync(int id, int rentalRequestRotationListId, RentalRequestRotationList item)
        {
            // update the rental request rotation list item.
            AdjustRRRLRecord(item);
            var exists = _context.RentalRequestRotationLists.Any(a => a.Id == rentalRequestRotationListId);

            if (exists && rentalRequestRotationListId == item.Id)
            {
                _context.RentalRequestRotationLists.Update(item);
                // Save the changes
                _context.SaveChanges();
                _context.Entry(item).State = EntityState.Detached;

                // now update the corresponding entry in the LocalAreaRotationList.
                _context.UpdateLocalAreaRotationList(item.Id);

                return(new ObjectResult(item));
            }
            else
            {
                // record not found
                return(new StatusCodeResult(404));
            }
        }
Beispiel #8
0
        /// <summary>
        /// Update rental request rotation list
        /// </summary>
        /// <remarks>Updates a rental request rotation list entry</remarks>
        /// <param name="id">id of RentalRequest to update</param>
        /// <param name="item"></param>
        /// <response code="200">OK</response>
        /// <response code="404">RentalRequestRotationList not found</response>
        public virtual IActionResult RentalrequestRotationListIdPutAsync(int id, RentalRequestRotationList item)
        {
            // update the rental request rotation list item
            AdjustRentalRequestRotationListRecord(item);

            // check if we have the rental request and the rotation list is attached
            bool exists = _context.RentalRequests.Any(a => a.Id == id);

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

            // check if we have the rental request that is In Progress
            exists = _context.RentalRequests
                     .Any(a => a.Id == id &&
                          a.Status.Equals("In Progress", StringComparison.InvariantCultureIgnoreCase));

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

            exists = _context.RentalRequests
                     .Any(a => a.Id == id &&
                          a.Status.Equals("In Progress", StringComparison.InvariantCultureIgnoreCase) &&
                          a.RentalRequestRotationList.Any(b => b.Id == item.Id));

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

            // ******************************************************************
            // update the rental request rotation list record
            // and count the "Yes"es
            // ******************************************************************
            RentalRequest rentalRequest = _context.RentalRequests
                                          .AsNoTracking()
                                          .Include(x => x.RentalRequestRotationList)
                                          .ThenInclude(e => e.Equipment)
                                          .Include(x => x.DistrictEquipmentType)
                                          .ThenInclude(d => d.EquipmentType)
                                          .Include(x => x.LocalArea)
                                          .First(a => a.Id == id);

            _context.Entry(rentalRequest).State = EntityState.Detached;

            // ******************************************************************
            // find the rotation list record to update
            // ******************************************************************
            int rotationListIndex = -1;

            for (int i = 0; i < rentalRequest.RentalRequestRotationList.Count; i++)
            {
                if (rentalRequest.RentalRequestRotationList[i].Id == item.Id)
                {
                    rotationListIndex = i;
                    break;
                }
            }

            // ******************************************************************
            // update the rental request rotation list record
            // ******************************************************************
            rentalRequest.RentalRequestRotationList[rotationListIndex] = item;

            // to do: fix the CreateTimestamp and UserId - coming in as nulls

            // ******************************************************************
            // can we "Complete" this rental request
            // (if the Yes or Forced Hires = Request.EquipmentCount)
            // ******************************************************************
            int countOfYeses          = 0;
            int equipmentRequestCount = rentalRequest.EquipmentCount;

            foreach (RentalRequestRotationList rotationList in rentalRequest.RentalRequestRotationList)
            {
                if (rotationList.OfferResponse != null &&
                    rotationList.OfferResponse.Equals("Yes", StringComparison.InvariantCultureIgnoreCase))
                {
                    countOfYeses = countOfYeses + 1;
                }
                else if (rotationList.IsForceHire != null &&
                         rotationList.IsForceHire == true)
                {
                    countOfYeses = countOfYeses + 1;
                }
            }

            if (countOfYeses >= equipmentRequestCount)
            {
                rentalRequest.Status = "Complete";
                rentalRequest.FirstOnRotationList = null;
            }

            // ******************************************************************
            // If the request is still In Progress:
            // 1. get the number of blocks for this equipment type
            // 2. set which rotation list record is currently "active"
            // ******************************************************************
            if (!rentalRequest.Status.Equals("Complete", StringComparison.InvariantCultureIgnoreCase))
            {
                int numberOfBlocks = GetNumberOfBlocks(rentalRequest);
                UpdateLocalAreaRotationList(rentalRequest, numberOfBlocks);
            }

            // ******************************************************************
            // save the changes - Rental Request
            // ******************************************************************
            _context.RentalRequests.Update(rentalRequest);
            _context.SaveChanges();

            return(new ObjectResult(new HetsResponse(item)));
        }
Beispiel #9
0
 public bool SetLockedLocation(Location location)
 {
     _context.Entry(location).State = EntityState.Modified;
     _context.SaveChanges();
     return(location.Locked);
 }
Beispiel #10
0
        /// <summary>
        /// Get business user record
        /// </summary>
        /// <param name="context"></param>
        /// <param name="httpContext"></param>
        /// <param name="userId"></param>
        /// <param name="businessGuid"></param>
        /// <param name="guid"></param>
        /// <returns></returns>
        public static HetBusinessUser GetBusinessUser(DbAppContext context, HttpContext httpContext, string userId, string businessGuid, string guid = null)
        {
            // find the business
            HetBusiness business = context.HetBusiness.AsNoTracking()
                                   .FirstOrDefault(x => x.BceidBusinessGuid.ToLower().Trim() == businessGuid.ToLower().Trim());

            // setup the business
            if (business == null)
            {
                business = new HetBusiness
                {
                    BceidBusinessGuid          = businessGuid.ToLower().Trim(),
                    AppCreateUserDirectory     = "BCeID",
                    AppCreateUserGuid          = guid,
                    AppCreateUserid            = userId,
                    AppCreateTimestamp         = DateTime.UtcNow,
                    AppLastUpdateUserDirectory = "BCeID",
                    AppLastUpdateUserGuid      = guid,
                    AppLastUpdateUserid        = userId,
                    AppLastUpdateTimestamp     = DateTime.UtcNow
                };

                // get additional business data
                string legalName      = httpContext.Request.Headers[ConstSiteMinderBusinessLegalName];
                string businessNumber = httpContext.Request.Headers[ConstSiteMinderBusinessNumber];

                if (!string.IsNullOrEmpty(legalName))
                {
                    business.BceidLegalName = legalName;
                }

                if (!string.IsNullOrEmpty(businessNumber))
                {
                    business.BceidBusinessNumber = businessNumber;
                }

                // save record
                context.HetBusiness.Add(business);
                context.SaveChanges();
            }
            else
            {
                // update business information
                string legalName      = httpContext.Request.Headers[ConstSiteMinderBusinessLegalName];
                string businessNumber = httpContext.Request.Headers[ConstSiteMinderBusinessNumber];

                if (!string.IsNullOrEmpty(legalName))
                {
                    business.BceidLegalName = legalName;
                }

                if (!string.IsNullOrEmpty(businessNumber))
                {
                    business.BceidBusinessNumber = businessNumber;
                }

                business.AppLastUpdateUserDirectory = "BCeID";
                business.AppLastUpdateUserGuid      = guid;
                business.AppLastUpdateUserid        = userId;
                business.AppLastUpdateTimestamp     = DateTime.UtcNow;

                context.SaveChanges();
            }

            // ok - now find the user
            HetBusinessUser user = context.HetBusinessUser
                                   .FirstOrDefault(x => x.BusinessId == business.BusinessId &&
                                                   x.BceidUserId == userId);

            if (user == null)
            {
                // auto register the user
                user = new HetBusinessUser
                {
                    BceidUserId                = userId,
                    BceidGuid                  = guid,
                    BusinessId                 = business.BusinessId,
                    AppCreateUserDirectory     = "BCeID",
                    AppCreateUserGuid          = guid,
                    AppCreateUserid            = userId,
                    AppCreateTimestamp         = DateTime.UtcNow,
                    AppLastUpdateUserDirectory = "BCeID",
                    AppLastUpdateUserGuid      = guid,
                    AppLastUpdateUserid        = userId,
                    AppLastUpdateTimestamp     = DateTime.UtcNow
                };

                // get additional user data
                string displayName = httpContext.Request.Headers[ConstSiteMinderUserDisplayName];
                string email       = httpContext.Request.Headers[ConstSiteMinderEmail];

                if (!string.IsNullOrEmpty(displayName))
                {
                    user.BceidDisplayName = displayName;
                }

                if (!string.IsNullOrEmpty(email))
                {
                    user.BceidEmail = email;
                }

                // add the "Business Logon" role
                HetBusinessUserRole userRole = new HetBusinessUserRole
                {
                    RoleId                     = StatusHelper.GetRoleId("Business BCeID", context),
                    EffectiveDate              = DateTime.UtcNow.AddMinutes(-10),
                    AppCreateUserDirectory     = "BCeID",
                    AppCreateUserGuid          = guid,
                    AppCreateUserid            = userId,
                    AppCreateTimestamp         = DateTime.UtcNow,
                    AppLastUpdateUserDirectory = "BCeID",
                    AppLastUpdateUserGuid      = guid,
                    AppLastUpdateUserid        = userId,
                    AppLastUpdateTimestamp     = DateTime.UtcNow
                };

                user.HetBusinessUserRole.Add(userRole);

                // save record
                context.HetBusinessUser.Add(user);
                context.SaveChanges();
            }
            else
            {
                // update the user
                string displayName = httpContext.Request.Headers[ConstSiteMinderUserDisplayName];
                string email       = httpContext.Request.Headers[ConstSiteMinderEmail];

                if (!string.IsNullOrEmpty(displayName))
                {
                    user.BceidDisplayName = displayName;
                }

                if (!string.IsNullOrEmpty(email))
                {
                    user.BceidEmail = email;
                }

                context.SaveChanges();
            }

            // get complete user record (with roles) and return
            user = context.HetBusinessUser.AsNoTracking()
                   .Where(x => x.BusinessId == business.BusinessId &&
                          x.BceidUserId == userId)
                   .Include(u => u.HetBusinessUserRole)
                   .ThenInclude(r => r.Role)
                   .ThenInclude(rp => rp.HetRolePermission)
                   .ThenInclude(p => p.Permission)
                   .FirstOrDefault();

            // detach user and return
            if (user != null)
            {
                context.Entry(user).State = EntityState.Detached;
            }

            return(user);
        }
Beispiel #11
0
        /// <summary>
        /// Get user record
        /// </summary>
        /// <param name="context"></param>
        /// <param name="userId"></param>
        /// <param name="guid"></param>
        /// <returns></returns>
        public static HetUser GetUser(DbAppContext context, string userId, string guid = null)
        {
            HetUser user = null;

            if (!string.IsNullOrEmpty(guid))
            {
                user = GetUserByGuid(guid, context);
            }

            if (user == null)
            {
                user = GetUserBySmUserId(userId, context);
            }

            if (user == null)
            {
                return(null);
            }

            if (!string.IsNullOrEmpty(guid) && string.IsNullOrEmpty(user.Guid))
            {
                // self register (write the users Guid to the db)
                int updUserId = user.UserId;

                using (IDbContextTransaction transaction = context.Database.BeginTransaction())
                {
                    // lock the table during this transaction
                    context.Database.ExecuteSqlCommand(@"LOCK TABLE ""HET_USER"" IN EXCLUSIVE MODE;");

                    HetUser updUser = context.HetUser.First(x => x.UserId == updUserId);

                    updUser.Guid = guid;
                    updUser.AppLastUpdateUserDirectory = user.SmAuthorizationDirectory;
                    updUser.AppLastUpdateUserGuid      = guid;
                    updUser.AppLastUpdateUserid        = userId;
                    updUser.AppLastUpdateTimestamp     = DateTime.UtcNow;

                    context.HetUser.Update(updUser);

                    // update user record
                    context.SaveChanges();

                    // commit
                    transaction.Commit();
                }

                // update the user object for the current session
                user.Guid = guid;
                user.AppLastUpdateUserDirectory = user.SmAuthorizationDirectory;
                user.AppLastUpdateUserGuid      = guid;
                user.AppLastUpdateUserid        = userId;
                user.AppLastUpdateTimestamp     = DateTime.UtcNow;
            }
            else if (!string.IsNullOrEmpty(user.Guid) &&
                     !string.IsNullOrEmpty(guid) &&
                     !user.Guid.Equals(guid, StringComparison.OrdinalIgnoreCase))
            {
                // invalid account - guid doesn't match user credential
                return(null);
            }

            // detach user and return
            context.Entry(user).State = EntityState.Detached;
            return(user);
        }