Exemple #1
0
        /// <summary>
        /// Method to save a resident's shift
        /// </summary>
        /// <param name="shift"></param>
        /// <param name="overrideAcknowledged">Indication the user has chosen to overwrite existing shifts</param>
        /// <returns></returns>
        public ResponseModel <Tuple <ResidentShiftModel, IEnumerable <ResidentShiftModel> > > SaveShift(ResidentShiftModel shift)
        {
            // NOTE: THIS SECTION CONTAINS CHANGES ADDED AFTER THE
            //    DEADLINE, TO RESOLVE BUG PERSISTING TIME ENTRIES
            Func <Tuple <ResidentShiftModel, IEnumerable <ResidentShiftModel> > > func = () =>
            {
                var shifts    = _residentRepo.FindShiftsByResidentId(shift.InstitutionResidentId).Result.ToList();
                var conflicts = shifts.Where(s => DoesShiftConflict(s, shift)).ToList();

                if (conflicts.Any() && !shift.OverrideAcknowleded)
                {
                    throw new ShiftConflictException()
                          {
                              Conflicts = conflicts
                          };
                }

                using (var scope = new TransactionScope())
                {
                    conflicts.ForEach(c => _residentRepo.Delete(c));
                    var response = _residentRepo.Save(shift);
                    if (!response.HasError)
                    {
                        shift = response.Result;
                    }

                    scope.Complete();
                }
                shifts = _residentRepo.FindShiftsByResidentId(shift.InstitutionResidentId).Result.ToList();
                return(new Tuple <ResidentShiftModel, IEnumerable <ResidentShiftModel> >(shift, shifts));
            };

            return(Execute(func));
        }
Exemple #2
0
        public IHttpActionResult GetResidentShifts(int residentId)
        {
            try
            {
                HttpRequires.IsTrue(residentId > 0, "A valid resident identifier is required");

                var response = _residentRepo.FindShiftsByResidentId(residentId);

                HttpAssert.Success(response);
                HttpAssert.NotNull(response, String.Format("Unable to find shifts for resident with id [{0}]", residentId));

                return(Ok(response.Result));
            }
            catch (Exception ex)
            {
                if (_logger != null)
                {
                    _logger.Write(ex);
                }
                return(InternalServerError());
            }
        }