Example #1
0
        public IHttpActionResult SwitchStatusPlanLocation(int id)
        {
            try
            {
                PlanLocation planLocation = _planService.FindPlanLocation(id);

                planLocation.Done = !planLocation.Done;
                bool result = _planService.UpdatePlanLocation(planLocation);

                if (result)
                {
                    return(Ok());
                }
                else
                {
                    return(BadRequest());
                }
            }
            catch (Exception ex)
            {
                _loggingService.Write(GetType().Name, nameof(AddLocationToPlan), ex);

                return(InternalServerError(ex));
            }
        }
Example #2
0
 public void Save(string userId, PlanLocation location)
 {
     if (location.Id == 0)
     {
         var user = CurrentUser(userId);
         location.User = user;
         user.Locations.Add(location);
     }
     else
     {
         var old = Get(userId, location.Id);
         old.Latitude     = location.Latitude;
         old.LocationType = location.LocationType;
         old.Longitude    = location.Longitude;
         old.Title        = location.Title;
     }
 }
Example #3
0
        public bool UpdatePlanLocation(PlanLocation entity)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
                {
                    _planLocationRepository.Update(entity);
                    _unitOfWork.SaveChanges();

                    scope.Complete();
                    return(true);
                } //end scope
            }
            catch (Exception ex)
            {
                _loggingService.Write(GetType().Name, nameof(UpdatePlanLocation), ex);
                return(false);
            }
        }
Example #4
0
        public bool AddLocationToPlan(PlanLocation planLocation)
        {
            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    _planLocationRepository.Create(planLocation);
                    _unitOfWork.SaveChanges();

                    scope.Complete();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                _loggingService.Write(GetType().Name, nameof(AddLocationToPlan), ex);

                return(false);
            }
        }
Example #5
0
        public IHttpActionResult UpdatePlanNote(UpdatePlanNoteViewModels noteLocation)
        {
            try
            {
                PlanLocation updatePlanLocation = _planService.FindPlanLocation(noteLocation.NoteId);
                updatePlanLocation.Index = noteLocation.Index;
                bool result = _planService.UpdatePlanLocation(updatePlanLocation);

                if (result)
                {
                    return(Ok());
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                _loggingService.Write(GetType().Name, nameof(AddLocationToPlan), ex);

                return(InternalServerError(ex));
            }
        }
Example #6
0
        public IHttpActionResult AddLocationToPlan(LocationInPlanViewModels planLocation)
        {
            try
            {
                PlanLocation location = ModelBuilder.ConvertToModels(planLocation);


                if (!planLocation.Index.HasValue)
                {
                    Plan plan = _planService.Find(planLocation.PlanId, _ => _.PlanLocations, _ => _.Notes);

                    IEnumerable <PlanLocation> planLocations = plan.PlanLocations;
                    IEnumerable <Note>         planNotes     = plan.Notes;

                    int maxLocationIndex = planLocations.OrderByDescending(_ => _.Index).FirstOrDefault() != null
                        ? planLocations.OrderByDescending(_ => _.Index).FirstOrDefault().Index
                        : 0;

                    int maxPlanIndex = planNotes.OrderByDescending(_ => _.Index).FirstOrDefault() != null
                        ? planNotes.OrderByDescending(_ => _.Index).FirstOrDefault().Index
                        : 0;

                    location.Index = (maxLocationIndex > maxPlanIndex ? maxLocationIndex : maxPlanIndex) + 1;
                } //end if identity max index

                bool result = _planService.AddLocationToPlan(location);

                if (result)
                {
                    return(Ok());
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                _loggingService.Write(GetType().Name, nameof(AddLocationToPlan), ex);

                return(InternalServerError(ex));
            }
        }
Example #7
0
        public PlanDetailLocationViewModels ConvertToPlanDetailLocationViewModels(PlanLocation planLocation)
        {
            int   ratingCount = planLocation.Location.Reviews.Count;
            float rating      = planLocation.Location.Reviews.Sum(_ => _.Rating) / ratingCount;

            rating = float.IsNaN(rating) ? 0 : rating;

            return(new PlanDetailLocationViewModels
            {
                PlanLocationId = planLocation.Id,
                LocationId = planLocation.LocationId,
                Address = planLocation.Location.Address,
                Photo = planLocation.Location.Photos.FirstOrDefault(_ => _.IsPrimary)?.Photo.Path.ToString(),
                Title = planLocation.Location.Name,
                Rating = rating,
                ReviewCount = ratingCount,
                Index = planLocation.Index,
                PlanDay = planLocation.PlanDay,
                Category = planLocation.Location.Category,
                IsDone = planLocation.Done,
                TotalTimeStay = planLocation.Location.TotalTimeStay
            });
        }