public void SetUp()
        {
            validGoalId = Guid.NewGuid();

            validViewModel = new GoalViewModel
            {
                Amount    = 1,
                Complete  = true,
                EndDate   = DateTime.Now,
                Id        = Guid.NewGuid(),
                Name      = "TEST",
                StartDate = DateTime.MaxValue,
                UserId    = Guid.NewGuid()
            };

            validGoals = new List <GoalProxy>
            {
                new GoalProxy
                {
                    Amount    = 1,
                    Complete  = true,
                    EndDate   = DateTime.Now,
                    Id        = Guid.NewGuid(),
                    Name      = "TEST",
                    StartDate = DateTime.Now,
                    UserId    = Guid.NewGuid()
                }
            };

            assembler = new GoalAssembler();
        }
예제 #2
0
        public HttpResponseMessage Update(HttpRequestMessage request, GoalViewModel goalViewModel)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, "Invalid goal specification");
                }
                else
                {
                    var goal = Mapper.Map <GoalViewModel, Goal>(goalViewModel);
                    //Goal goalToUpdate = new Goal();
                    //goalToUpdate.UpdateGoal(goal);

                    //todo: (this is temporary), change the business for the user mapping problem in UserProfile
                    var userProfile = _userProfileRepository.GetSingle(goal.UserProfileId);
                    goal.UserProfile = userProfile;

                    _goalRepository.Edit(goal);
                    UnitOfWork.Commit();

                    GoalViewModel goalUpdated = Mapper.Map <Goal, GoalViewModel>(goal);
                    response = request.CreateResponse(HttpStatusCode.Created, goalUpdated);
                }

                return response;
            }));
        }
예제 #3
0
        public async Task <bool> CreateAsync(GoalViewModel goalViewModel)
        {
            if (string.IsNullOrEmpty(goalViewModel.Title) ||
                string.IsNullOrEmpty(goalViewModel.CalendarId))
            {
                throw new ArgumentException(InvalidPropertyErrorMessage);
            }

            var goal = new Goal
            {
                Title         = goalViewModel.Title,
                CalendarId    = goalViewModel.CalendarId,
                ColorId       = goalViewModel.ColorId,
                StartDateTime = DateTime.Now,
                IsActive      = true,
            };

            goal.DayTime   = this.enumParseService.Parse <DayTime>(goalViewModel.DayTime);
            goal.Duration  = this.enumParseService.Parse <Duration>(goalViewModel.Duration);
            goal.Frequency = this.enumParseService.Parse <Frequency>(goalViewModel.Frequency);

            await this.goalRepository.AddAsync(goal);

            var result = await this.goalRepository.SaveChangesAsync();

            await this.habitService.GenerateHabitsAsync(goal, goal.StartDateTime);

            return(result > 0);
        }
예제 #4
0
        public HttpResponseMessage CreateGoal(HttpRequestMessage request, GoalViewModel goal)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response;

                if (!ModelState.IsValid)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    var newGoal = new Goal();
                    newGoal.CreateGoal(goal);

                    // Asign goal to a user
                    var userProfile = _userProfileRepository.GetSingle(goal.UserProfileId);
                    newGoal.UserProfile = userProfile;

                    _goalRepository.Add(newGoal);
                    UnitOfWork.Commit();

                    goal = Mapper.Map <Goal, GoalViewModel>(newGoal);
                    response = request.CreateResponse(HttpStatusCode.Created, goal);
                }

                return response;
            }));
        }
예제 #5
0
        public static GoalViewModel ToViewModel(this IGoal goal)
        {
            var vm = new GoalViewModel();

            CopyFields(goal, vm);
            return(vm);
        }
예제 #6
0
        private void RemoveGoal_Clicked(object sender, EventArgs e)
        {
            var vm = new GoalViewModel(tappedGoalItem);

            vm.RemoveGoal.Execute(tappedGoalItem);
            Background_tapped(sender, e);
        }
예제 #7
0
        public void Data()
        {
            // Arrange
            var goalModelData = "data";
            var goalModel     = new GoalViewModel()
            {
                Data = goalModelData
            };

            var userId = FakeUserId;

            this.userManagerMock
            .Setup(x => x.GetUserId(It.IsAny <ClaimsPrincipal>()))
            .Returns(userId.ToString());

            // Act
            var actionResult = this.controller.Data(goalModel);

            // Assert
            this.goalManagerMock.Verify(
                x => x.Create(It.Is <Goal>(
                                  g => g.Data == goalModelData &&
                                  g.UserId == userId &&
                                  g.GoalId != Guid.Empty)),
                Times.Once);
        }
예제 #8
0
        /// <summary>
        ///     Modifies a goal.
        /// </summary>
        /// <param name="goal">The goal.</param>
        /// <param name="username">The username.</param>
        /// <returns>
        ///     The response object.
        /// </returns>
        public async Task <OrchestratorResponseWrapper <GoalViewModel> > EditGoal(GoalViewModel goal, string username)
        {
            var response = new OrchestratorResponseWrapper <GoalViewModel>();

            try
            {
                var request     = assembler.NewEditGoalRequest(goal, username);
                var apiResponse = await dataAccess.EditGoal(request);

                if (!apiResponse.Success)
                {
                    response.AddErrors(apiResponse.Errors);
                }
                else
                {
                    response.Model = assembler.ProxyToViewModel(apiResponse.Goal);
                }

                response.AddWarnings(apiResponse.Warnings);
            }
            catch (Exception ex)
            {
                var err = errorHelper.Create(ex, username, GetType(), "EditGoal");
                response.AddError(err);
            }

            return(response);
        }
        public ActionResult GoalEdit()
        {
            var userId      = User.Identity.GetUserId();
            var userProfile = _context.UserProfiles.FirstOrDefault(x => x.Id == userId);

            if (userProfile != null)
            {
                GoalViewModel model = new GoalViewModel
                {
                    FirstGoals   = _context.FirstGoals.Where(x => x.UserProfileId == userId).ToList(),
                    SecondGoals  = _context.SecondGoals.Where(x => x.UserProfileId == userId).ToList(),
                    ThirdGoals   = _context.ThirdGoals.Where(x => x.UserProfileId == userId).ToList(),
                    FourthGoals  = _context.FourthGoals.Where(x => x.UserProfileId == userId).ToList(),
                    FifthGoals   = _context.FifthGoals.Where(x => x.UserProfileId == userId).ToList(),
                    SixthGoals   = _context.SixthGoals.Where(x => x.UserProfileId == userId).ToList(),
                    SeventhGoals = _context.SeventhGoals.Where(x => x.UserProfileId == userId).ToList(),
                    EightGoals   = _context.EighthGoals.Where(x => x.UserProfileId == userId).ToList()
                };
                return(View(model));
            }
            else
            {
                return(RedirectToAction("Manage", "Profile"));
            }
        }
예제 #10
0
 public async Task <IActionResult> AddEdit(GoalViewModel vm)
 {
     if (ModelState.IsValid)
     {
         var user = _userManager.GetUserId(HttpContext.User);
         if (vm.GoalId > 0)
         {
             var goal = _goalRepository.GetById(vm.GoalId);
             if (goal == null)
             {
                 return(RedirectToAction("Index"));
             }
             vm.ModifiedBy  = user;
             vm.CreatedBy   = goal.CreatedBy;
             vm.DateCreated = goal.DateCreated;
             goal           = Mapper.Map <GoalViewModel, Goal>(vm);
             await _goalRepository.UpdateAsync(goal);
         }
         else
         {
             vm.CreatedBy  = user;
             vm.ModifiedBy = user;
             var goal = Mapper.Map <GoalViewModel, Goal>(vm);
             await _goalRepository.CreateAsync(goal);
         }
         return(RedirectToAction("Index"));
     }
     return(View("~/Views/Shared/_AddEditGoal.cshtml", vm));
 }
        public void MapGoalViewModelToGoal_WithWithNullOrEmptyArgument_ShouldThrowAnArgumentException(string id)
        {
            var exeptionErrorMessage = "One or more required properties are null.";

            var correctGoal = new GoalViewModel
            {
                Title      = "Test",
                ColorId    = 1,
                CalendarId = "1",
                DayTime    = DayTime.Afternoon.ToString(),
                Duration   = Duration.HourAndHalf.ToString(),
                Frequency  = Frequency.EveryDay.ToString(),
            };

            GoalViewModel incorrectGoal = null;

            var exeption1 = Assert.Throws <ArgumentException>(() =>
                                                              this.goalService.MapGoalViewModelToGoal(correctGoal, id));
            var exeption2 = Assert.Throws <ArgumentException>(() =>
                                                              this.goalService.MapGoalViewModelToGoal(incorrectGoal, id));
            var exeption3 = Assert.Throws <ArgumentException>(() =>
                                                              this.goalService.MapGoalViewModelToGoal(incorrectGoal, "1"));

            Assert.Equal(exeptionErrorMessage, exeption1.Message);

            Assert.Equal(exeptionErrorMessage, exeption2.Message);

            Assert.Equal(exeptionErrorMessage, exeption3.Message);
        }
        public Goal OutOfGoalViewModel(GoalViewModel goalViewModel, string username)
        {
            Sports sports = new Sports(SessionProvider.CurrentSession);
            Venues venues = new Venues(SessionProvider.CurrentSession);
            Goals goals = new Goals(SessionProvider.CurrentSession);
            Users users = new Users(SessionProvider.CurrentSession);

            Goal goal;
            if(goalViewModel.Id == 0)
            {
                goal = new Goal();
                goal.CreatedOn = DateTime.Now;
                goal.UserCreator = users.GetByUserName(username);
            }
            else
            {
                goal = goals.GetById(goalViewModel.Id);
            }
            
            goal.Name = goalViewModel.Name;
            goal.Date = goalViewModel.Date;
            goal.Description = goalViewModel.Description;

            goal.Web = goalViewModel.Web;
            goal.Venue = venues.GetById(Convert.ToInt32(goalViewModel.VenueId));
            goal.Sport = sports.GetById(Convert.ToInt32(goalViewModel.SportId));

            goal.Venue.Latitude = Convert.ToInt32(goalViewModel.VenueLatitude);
            goal.Venue.Longitude = Convert.ToInt32(goalViewModel.VenueLongitude);

            return goal;
        }
        public ActionResult CheckGoalStatus()
        {
            var activityList = new List <ActivityViewModel>();

            var    goal       = _goalRepository.GetLastIncompleteGoalbyUserId(WebSecurity.CurrentUserId);
            var    activities = _activityRepository.GetActivityFromStartDateToEndDate(goal.CreatedOn, goal.EndOn);
            double calorie    = 0;
            double distance   = 0;

            foreach (var a in activities)
            {
                calorie  = calorie + a.Calorie;
                distance = distance + a.Distance;
            }
            bool isCalorieAchieved  = calorie >= goal.Calorie;
            bool isDistanceAchieved = distance >= goal.Distance;

            if (isDistanceAchieved && isCalorieAchieved)
            {
                goal.IsAchieved = true;
                _goalRepository.Edit(goal);
            }

            var goalViewModel = new GoalViewModel
            {
                AchievedDistance = distance,
                AchivedCalorie   = calorie,
                GoalCalorie      = goal.Calorie,
                GaolDistance     = goal.Distance,
                IsAchieved       = goal.IsAchieved
            };

            return(View(goalViewModel));
        }
        public async Task <IActionResult> ViewGoal(long ID)
        {
            FitnessUser currentUser = await GetUser();

            Goal goal = await storageService.GetGoalByID(currentUser, ID);

            if (goal == null)
            {
                return(BadRequest());
            }

            GoalProgress[] progress = await storageService.GetGoalProgress(currentUser, ID);

            if (progress == null)
            {
                return(BadRequest());
            }

            GoalViewModel viewModel = new GoalViewModel()
            {
                Goal     = goal,
                Progress = progress
            };

            return(View(viewModel));
        }
예제 #15
0
 public void Put([FromBody] GoalViewModel model)
 {
     if (TryValidateModel(model))
     {
         var goalDto = _mapper.Map <GoalDto>(model);
         _goalService.UpdateGoal(goalDto);
     }
 }
        //Update Goal

        public Guid UpdateGola(GoalViewModel model)
        {
            if (ModelState.IsValid)
            {
                Goal entity = MapViewModelToModel(model);

                _service.Update(entity);
            }
            return(model.Id);
        }
        //Create Goal
        public Guid CreateGola(GoalViewModel model)
        {
            if (ModelState.IsValid)
            {
                Goal entity = MapViewModelToModel(model);

                return(_service.Create(entity));
            }
            throw new ApplicationException("Błąd");
        }
예제 #18
0
        /// <summary>
        /// Creates a new GoalViewModel with the current projectID
        /// and the logged in userID
        /// </summary>
        /// <returns></returns>
        private GoalViewModel CreateNewGoalModel()
        {
            GoalViewModel newGoalModel = new GoalViewModel()
            {
                ProjectID    = OpenProjectModel.ID,
                AspNetUserID = User.Identity.GetUserId()
            };

            return(newGoalModel);
        }
예제 #19
0
 public static Goal ToModel(this GoalViewModel viewModel)
 {
     return(new Goal
     {
         Id = viewModel.Id,
         Name = viewModel.Name,
         Description = viewModel.Description,
         State = viewModel.State
     });
 }
예제 #20
0
        /// <summary>
        /// Removes a goal from a project
        /// </summary>
        /// <param name="goalModel"></param>
        public void RemoveGoal(GoalViewModel goalModel)
        {
            Goal theGoal = _db.Goals.Find(goalModel.ID);

            if (theGoal != null)
            {
                _db.Goals.Remove(theGoal);
                _db.SaveChanges();
            }
        }
예제 #21
0
 public static void CreateGoal(this Goal goal, GoalViewModel goalVm)
 {
     goal.Name               = goalVm.Name;
     goal.Description        = goalVm.Description;
     goal.Estimation         = goalVm.Estimation;
     goal.GoalStatus         = Status.Open;
     goal.Progress           = 0;
     goal.TimeLogged         = TimeSpan.Zero;
     goal.RemainingEstimates = goalVm.Estimation;
     goal.DateCreated        = DateTime.Now;
 }
예제 #22
0
        public async Task <ActionResult <GoalViewModel> > PutDay(Guid id, [FromBody] GoalViewModel goalViewModel)
        {
            if (id != goalViewModel.Id)
            {
                return(BadRequest());
            }

            var goalYearPrevious = await _goalDayService.Update(goalViewModel.ToDayDb());

            return(goalYearPrevious.ToViewModel());
        }
예제 #23
0
        async void OnItemTapped(object sender, ItemTappedEventArgs e)
        {
            Goal tappedGoalItem = e.Item as Goal;

            var GoalViewModelVM = new GoalViewModel(tappedGoalItem);
            var GoalPopupMenu   = new UpdateGoalPopup(tappedGoalItem);

            GoalPopupMenu.CallbackEvent += (object sender, object e) => CallbackMethod();
            GoalPopupMenu.BindingContext = GoalViewModelVM;

            await PopupNavigation.Instance.PushAsync(GoalPopupMenu);
        }
예제 #24
0
        public async Task <HttpResponseMessage> Edit(GoalViewModel postedViewModel)
        {
            var mapper         = GetMapper();
            var entityUpdating = mapper.Map <GoalViewModel, Goal>(postedViewModel);
            var actionResult   = await businessService.UpdateGoalAsync(entityUpdating);

            if (actionResult.ReturnStatus == false)
            {
                return(CreateErrorResponse(actionResult));
            }

            return(CreateViewModelResponse(postedViewModel, actionResult));
        }
예제 #25
0
        public async Task <HttpResponseMessage> Add(GoalViewModel postedViewModel)
        {
            var mapper         = GetMapper();
            var entityCreating = mapper.Map <GoalViewModel, Goal>(postedViewModel);
            var entityCreated  = await businessService.CreateGoalAsync(entityCreating);

            if (entityCreated.ReturnStatus == false)
            {
                return(CreateErrorResponse(entityCreated));
            }
            postedViewModel = mapper.Map <GoalViewModel>(entityCreated.ResultValue);
            return(CreateViewModelResponse(postedViewModel, entityCreated));
        }
예제 #26
0
        public async Task <HttpResponseMessage> Delete(GoalViewModel postedViewModel)
        {
            var mapper          = GetMapper();
            var entityDeleteing = mapper.Map <GoalViewModel, Goal>(postedViewModel);
            var result          = await businessService.DeleteGoalAsync(entityDeleteing);

            if (result.ReturnStatus == false)
            {
                return(CreateErrorResponse(result));
            }

            return(CreateViewModelResponse(postedViewModel, result));
        }
예제 #27
0
 /// <summary>
 ///     Creates a new instance of the <see cref="GoalProxy" /> class.
 /// </summary>
 /// <param name="goal">The goal.</param>
 /// <returns>The goal proxy.</returns>
 private static GoalProxy ViewModelToProxy(GoalViewModel goal)
 {
     return(new GoalProxy
     {
         Amount = goal.Amount,
         Complete = goal.Complete,
         EndDate = goal.EndDate,
         Id = goal.Id,
         Name = goal.Name,
         StartDate = goal.StartDate,
         UserId = goal.UserId
     });
 }
        private bool TryRemoveGoalFromGroupedList(int goalId, GroupedGoals groupedGoals)
        {
            GoalViewModel toRemove = null;

            if ((toRemove = groupedGoals.FirstOrDefault(g => g.Id == goalId)) != null)
            {
                groupedGoals.Remove(toRemove);

                return(true);
            }

            return(false);
        }
예제 #29
0
 public static void UpdateGoal(this Goal goal, GoalViewModel goalVm)
 {
     goal.Id                 = goalVm.Id;
     goal.Name               = goalVm.Name;
     goal.Description        = goalVm.Description;
     goal.Estimation         = goalVm.Estimation;
     goal.GoalStatus         = goalVm.GoalStatus;
     goal.Progress           = goalVm.Progress;
     goal.RemainingEstimates = goalVm.Estimation;
     goal.DateCreated        = goalVm.DateCreated;
     goal.UserProfileId      = goalVm.UserProfileId;
     //todo: goal.UserProfile = goalVm.UserProfile
 }
예제 #30
0
        public async Task <ActionResult> Add(GoalViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(InvalidModelState(ModelState));
            }

            model.UserId = UserId;

            var response = await orchestrator.AddGoal(model, UserEmail);

            return(JsonResponse(response));
        }
        /// <summary>
        /// Implementors can modify both the source and destination objects
        /// </summary>
        /// <param name="source">Source object</param>
        /// <param name="destination">Destination object</param>
        public void Process(Goal source, GoalViewModel destination)
        {
            var totalCount = source.Tasks.Count;

            destination.ValueProcess =
                source.Tasks.Count(
                    it => string.Equals(it.Status?.Name, "inprocess", StringComparison.OrdinalIgnoreCase));
            destination.PercentProcess = totalCount != 0 ? (destination.ValueProcess * 100.0) / totalCount : 0;
            destination.ValueCompleted = source.Tasks.Count(
                it => string.Equals(it.Status?.Name, "done", StringComparison.OrdinalIgnoreCase));
            destination.PercentCompleted = totalCount != 0 ? (destination.ValueCompleted * 100.0) / totalCount : 0;
            destination.ValueReady       = totalCount - destination.ValueProcess - destination.ValueCompleted;
            destination.PercentReady     = 100.0 - destination.PercentProcess - destination.PercentCompleted;
        }