コード例 #1
0
        public GoalChangeModel GetEditChangeViewModelById(string goalId)
        {
            if (string.IsNullOrEmpty(goalId))
            {
                throw new ArgumentException(InvalidPropertyErrorMessage);
            }

            var goal          = this.goalRepository.All().Where(x => x.Id == goalId).To <GoalModel>().First();
            var goalViewModel = new GoalModel
            {
                Title      = goal.Title,
                Frequency  = this.enumParseService.GetEnumDescription(goal.Frequency.ToString(), typeof(Frequency)),
                DayTime    = this.enumParseService.GetEnumDescription(goal.DayTime.ToString(), typeof(DayTime)),
                Duration   = this.enumParseService.GetEnumDescription(goal.Duration.ToString(), typeof(Duration)),
                CalendarId = goal.CalendarId,
                ColorId    = goal.ColorId,
            };

            var goalChangeViewModel = new GoalChangeModel
            {
                GoalModel   = goalViewModel,
                DayTimes    = this.dayTimesDescriptions,
                Frequencies = this.frequenciesDescriptions,
                Durations   = this.durationsDescriptions,
                Calendars   = this.calendarService.GetAll(),
                Colors      = this.colorService.GetAllColors(),
            };

            return(goalChangeViewModel);
        }
コード例 #2
0
 public MainPage()
 {
     this.InitializeComponent();
     goalModel   = new GoalModel();
     DataContext = goalModel;
     ScrollToLastRow(null, null);
 }
コード例 #3
0
        public override Debt CreateEntity(GoalModel model, Goal goal)
        {
            var entity = new Debt()
            {
                ReasonTypeId = model.ReasonId,
                UserId       = User.Identity.GetUserId(),
                Goal         = goal,
            };

            entity.Goal.Name = model.Name;
            if (String.IsNullOrEmpty(model.Description))
            {
                model.Description = String.Empty;
            }
            entity.Goal.Description = model.Description;
            if (model.Notifications != null && model.Notifications.Any())
            {
                var notifications = model.Notifications.Select(i =>
                                                               new Notification
                {
                    IsEmailEnabled = i.Email,
                    IsSmsEnabled   = i.Sms,
                    ReleaseDate    = Convert.ToDateTime(i.Hour),
                    UserId         = User.Identity.GetUserId()
                });
                entity.Goal.Notifications = notifications;
            }
            return(entity);
        }
コード例 #4
0
        public async Task <bool> CreateFromAdminAsync(GoalModel goalModel)
        {
            if (string.IsNullOrEmpty(goalModel.Title) ||
                string.IsNullOrEmpty(goalModel.CalendarId) ||
                goalModel.ColorId <= 0)
            {
                throw new ArgumentException(InvalidPropertyErrorMessage);
            }

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

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

            await this.goalRepository.AddAsync(goal);

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

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

            return(result > 0);
        }
コード例 #5
0
        public async Task <ActionResult <GoalModel> > GetGoal([FromRoute] int goalId)
        {
            try
            {
                var result = await _repository.GetGoals(User.Claims.GetUserId(), goalId);

                var goal = result.FirstOrDefault();

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

                var response = new GoalModel
                {
                    GoalId      = goal.GoalId,
                    Weight      = goal.Weight,
                    WeightGoal  = goal.WeightGoal,
                    Height      = goal.Height,
                    StartDate   = goal.StartDate,
                    IsCompleted = goal.IsCompleted,
                    IsSuccess   = goal.IsSuccess
                };

                return(response);
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
コード例 #6
0
        public IActionResult Save(GoalModel goal)
        {
            var userID = _httpContextAccessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (!ModelState.IsValid)
            {
                var viewModel = new GoalFormViewModel
                {
                    Goal = goal,
                    DefaultCurrencySymbol = _accountService.GetUserDefaultCurrencySymbol(userID)
                };

                return(View("GoalForm", viewModel));
            }

            if (goal.ID == 0)
            {
                _goalService.AddGoal(goal);
            }
            else
            {
                _goalService.UpdateGoal(goal);
            }

            return(RedirectToAction("MainPage", "Transaction"));
        }
コード例 #7
0
        public async Task <int> AddGoalAsync(GoalModel goalModel)
        {
            goalModel.CheckForNull(nameof(goalModel));

            var goal = _mapper.Map <GoalModel, Goal>(goalModel);

            switch (goal.Type)
            {
            case (byte)GoalTypes.Debt:
            {
                CreateDebtTransaction(goal);
                break;
            }

            case (byte)GoalTypes.Loan:
            {
                CreateLoanTransaction(goal);
                break;
            }
            }

            _context.Goals.Add(goal);
            await _context.SaveChangesAsync();

            return(goal.ID);
        }
コード例 #8
0
        // GET: Goals/Create
        public ActionResult Create()
        {
            GoalModel model = new GoalModel();

            model.RULES.ToList().Add(new GoalRuleModel());
            return(View("Create", model));
        }
コード例 #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        /// <summary>
        /// Sprawdza czy dane są poprawne i tworzy pustą macierz kryteriów i dodaje do CB
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AcceptBtn_Click(object sender, RoutedEventArgs e)
        {
            if (GoalTextBox.Text != "")
            {
                Goal = new GoalModel()
                {
                    Name = GoalTextBox.Text
                }
            }
            ;
            else
            {
                MessageBox.Show("error");
            }
            foreach (var v in CriterionLst)
            {
                CrMatrix.AddCriterion(v.Name); //mamy ilość
            }
            ItemX.ItemsSource = CriterionLst.Select(x => x.Name);
            ItemY.ItemsSource = CriterionLst.Select(x => x.Name);

            foreach (var v in AlternativeLst)
            {
                AlMatrix.AddAlternative(v.Name); //mamy ilość
            }
            ItemAX.ItemsSource = AlternativeLst.Select(x => x.Name);
            ItemAY.ItemsSource = AlternativeLst.Select(x => x.Name);
        }
コード例 #10
0
        public bool Update(GoalModel model) // update an existing record
        {
            GoalModel x = Read(model.uid);

            x = model;
            return(_db.SaveChanges() == 1);
        }
コード例 #11
0
        public async Task <ActionResult <GoalModel> > CompleteGoal(int goalId)
        {
            try
            {
                var result = await _repository.CompleteGoal(goalId, User.Claims.GetUserId(), DateTime.Now);

                if (result == null)
                {
                    return(NotFound());
                }

                var response = new GoalModel
                {
                    GoalId      = result.GoalId,
                    Weight      = result.Weight,
                    WeightGoal  = result.WeightGoal,
                    Height      = result.Height,
                    StartDate   = result.StartDate,
                    IsCompleted = result.IsCompleted,
                    IsSuccess   = result.IsSuccess
                };

                return(response);
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
コード例 #12
0
 public GoalDetailPage(GoalModel inputGoal, bool isCompetitionPage)
 {
     this.IsCompetitionPage = isCompetitionPage;
     this.goal = inputGoal;
     InitializeComponent();
     UpdateDetailView();
     UpdateLeaderBoard();
     ChallengeHandler();
 }
コード例 #13
0
 private static Goal ToGoal(GoalModel goalModel)
 {
     return(new Goal
     {
         Id = goalModel.Id,
         Title = goalModel.Title,
         Count = goalModel.Count
     });
 }
コード例 #14
0
        private void RecurrentGoalHandler(string recurrentId)
        {
            List <GoalModel> ReccurrentGoalList = new List <GoalModel>();

            if (selectedTeam == null)
            {
                ReccurrentGoalList = recurrentGoals.Where(g => g.RecurrentId == recurrentId).ToList();
            }
            else
            {
                //Get all goal in recurrentGoals, that have the same challengeId
                var temp_goal = recurrentGoals.Where(t_g => t_g.RecurrentId == recurrentId).FirstOrDefault();
                ReccurrentGoalList = recurrentGoals.Where(t_g => t_g.ChallengeId == temp_goal.ChallengeId).ToList();
            }

            ReccurrentGoalList.Sort((x, y) => y.CreatedDate.CompareTo(x.CreatedDate));

            if (selectedTeam == null)
            {
                PopulateRecurrentGoalChart(ReccurrentGoalList);
            }
            else
            {
                List <GoalModel> FinalAckRecGoals = new List <GoalModel>();
                List <GoalModel> AckRecGoals      = new List <GoalModel>();
                List <DateTime>  UniqueDates      = new List <DateTime>();


                foreach (var g in ReccurrentGoalList)
                {
                    if (!UniqueDates.Contains(g.Deadline))
                    {
                        UniqueDates.Add(g.Deadline);
                        AckRecGoals.Add(g);
                    }
                }

                foreach (var g in AckRecGoals)
                {
                    int sum = 0;
                    foreach (var goal in ReccurrentGoalList)
                    {
                        if (g.Deadline == goal.Deadline)
                        {
                            sum += int.Parse(goal.CurrentValue);
                        }
                    }
                    //     g.CurrentValue = sum.ToString();
                    GoalModel goalboal = new GoalModel()
                    {
                        CurrentValue = sum.ToString(),
                    };
                    FinalAckRecGoals.Add(goalboal);
                }
                PopulateRecurrentGoalChart(FinalAckRecGoals);
            }
        }
コード例 #15
0
        // POST: api/GoalsApi
        public void Post([FromBody] string value)
        {
            GoalModel goalModel = JsonConvert.DeserializeObject <GoalModel>(value);

            if (goalModel != null)
            {
                string sqlInsertGaol = @"
INSERT INTO [dbo].[GOALS]
           ([NAME]
           ,[DESCR]
           ,[USR_ID]
           ,[USR_GROUP_ID]
           ,[USR_TYPE_ID]
           ,[FORMULA_TARGET]
           ,[NOTIFICATION_TYPE]
           ,[NOTIFICATION_IMAGE])
     VALUES
           ('" + goalModel.NAME + @"'
           ,'" + goalModel.DESCR + @"'
           ," + ((goalModel.USR_ID.HasValue) ? goalModel.USR_ID.Value.ToString() : "NULL") + @"
           ," + ((goalModel.USR_GROUP_ID.HasValue) ? goalModel.USR_GROUP_ID.Value.ToString() : "NULL") + @"
            ," + ((goalModel.USR_TYPE_ID.HasValue) ? goalModel.USR_TYPE_ID.Value.ToString() : "NULL") + @"
           ,'" + goalModel.FORMULA_TARGET.ToString() + @"'
           ," + goalModel.NOTIFICATION_TYPE.ToString() + @"
           ,'" + ((goalModel.USR_TYPE_ID.HasValue) ? goalModel.USR_TYPE_ID.Value.ToString() : "NULL") + @"')";


                using (SqlConnection con = new SqlConnection(DBSettings.ConnectionString))
                {
                    con.Open();

                    SqlCommand cmd = new SqlCommand(sqlInsertGaol);
                    cmd.Connection = con;

                    cmd.ExecuteNonQuery();



                    //               foreach(GoalRuleModel rule in goalModel.RULES)
                    //               {
                    //                   cmd.CommandText = @"INSERT INTO [dbo].[GOAL_RULES]
                    //      ([GOAL_ID]
                    //      ,[FORMULA]
                    //      ,[GOAL_LEVEL]
                    //      ,[ACHIEVEMENT_TITLE]
                    //      ,[ACHIEVEMENT_MESSAGE])
                    //VALUES
                    //      (<GOAL_ID, int,>
                    //      ,<FORMULA, varchar(max),>
                    //      ,<GOAL_LEVEL, tinyint,>
                    //      ,<ACHIEVEMENT_TITLE, varchar(1000),>
                    //      ,<ACHIEVEMENT_MESSAGE, varchar(max),>)";
                    //               }
                }
            }
        }
コード例 #16
0
ファイル: DataQueries.cs プロジェクト: glamberous/DasFinanzen
        private static GoalModel CreateNewGoalModel()
        {
            GoalModel newGoalModel = new GoalModel();

            newGoalModel.Amount  = Managers.Data.FileData.GoalModels.Count > 0 ? Managers.Data.FileData.GoalModels.Last().Amount : 1000.00m;
            newGoalModel.DateKey = string.Format($"{Managers.Data.Runtime.SelectedTime.Year}_{Managers.Data.Runtime.SelectedTime.Month}");
            newGoalModel.Save();
            Debug.Log($"New GoalModel with Key {newGoalModel.DateKey} was saved.");
            return(newGoalModel);
        }
コード例 #17
0
        public Goal Map(GoalModel goalModel)
        {
            if (goalModel == null)
            {
                return(new Goal());
            }

            var goal = ToGoal(goalModel);

            return(goal);
        }
コード例 #18
0
        private static GoalModel ToGoalModel(Goal goal)
        {
            var goalModel = new GoalModel
            {
                Id    = goal.Id,
                Title = goal.Title,
                Count = goal.Count
            };

            return(goalModel);
        }
コード例 #19
0
        public void MapGoalModelToGoal_ShouldMapCorrectly(
            GoalModel goalModel,
            GoalMapper sut)
        {
            // Act
            var result = sut.Map(goalModel);

            // Asserts
            result.Should().BeOfType <Goal>();
            result.Should().BeEquivalentTo(goalModel,
                                           opt => opt.Excluding(src => src.Id));
        }
コード例 #20
0
        public int CreateProjectGoal(GoalModel goalModel)
        {
            // Mapp to backend model
            var goal = new ProjectGoal();

            if (goalModel != null)
            {
                goal = ApplicationMapper.MapProjectGoal(goalModel);
            }
            // Create P.Goal
            return(projectRepository.CreateProjectGoal(goal));
        }
コード例 #21
0
        public void UpdateProjectGoal(GoalModel goalModel)
        {
            // Mapp to backend model
            var goal = new ProjectGoal();

            if (goalModel != null)
            {
                goal = ApplicationMapper.MapProjectGoal(goalModel);
            }
            // Create P.Goal
            projectRepository.UpdateProjectGoal(goal);
        }
コード例 #22
0
 public ActionResult Create(GoalModel goal)
 {
     try
     {
         apiController.Post(JsonConvert.SerializeObject(goal));
         return(View(goal));
     }
     catch (Exception e)
     {
         ModelState.AddModelError(string.Empty, "Server Error. Please contact administrator.");
         return(View());
     }
 }
コード例 #23
0
ファイル: ApplicationMapper.cs プロジェクト: cllp/pp
        public static ProjectGoal MapProjectGoal(GoalModel goalModel)
        {
            var goal = new ProjectGoal
            {
                Id             = goalModel.Id,
                ProjectId      = goalModel.ProjectId,
                GoalDefinition = goalModel.GoalDefinition,
                MesaureMethod  = goalModel.MesaureMethod,
                Achieved       = goalModel.Achieved,
                Type           = goalModel.Type
            };

            return(goal);
        }
コード例 #24
0
        public static bool CreateNewGoal(GoalModel Goal)
        {
            if (Goal == null)
            {
                return(false);
            }

            using (var db = new GoalContext())
            {
                db.Goals.Add(Goal);
                db.SaveChanges();
                return(true);
            }
        }
コード例 #25
0
        public async Task <IActionResult> Put(
            [FromBody] GoalModel goalModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var goal        = GoalMapper.Map(goalModel);
            var goalUpdated = await GoalService.UpdateAsync(goal);

            return(goalUpdated
                ? NoContent()
                : StatusCode((int)HttpStatusCode.NotModified));
        }
コード例 #26
0
        public int Insert(GoalModel obj)
        {
            var sql = @"
				INSERT INTO goal
				(
					name
				)
				VALUES
				(
					@Name
				);
				SELECT last_insert_rowid();
				"                ;

            return(Insert <GoalModel>(sql, obj));
        }
コード例 #27
0
        public int Insert(GoalModel obj)
        {
            // arrange
            var goalModel = new GoalModel()
            {
                Name = "Goal Name"
            };

            // act
            var newId = new GoalRepository().Insert(goalModel);

            // assert
            Assert.IsTrue(newId > 0);

            return(newId);
        }
コード例 #28
0
        public async Task <IActionResult> Post(
            [FromBody] GoalModel goalModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var goal        = GoalMapper.Map(goalModel);
            var createdGoal = await GoalService.CreateAsync(goal);

            goalModel = GoalMapper.Map(createdGoal);

            return(goalModel != null
                ? Created(string.Empty, goalModel) as IActionResult
                : StatusCode((int)HttpStatusCode.NotModified));
        }
コード例 #29
0
        public async Task Put_WhenInvalidModelState_ShouldReturnBadRequest(
            GoalModel goalModel,
            GoalController sut)
        {
            // Arranges
            sut.ModelState.AddModelError("Error key", "Error message");

            // Act
            var result = await sut.Put(goalModel);

            // Asserts
            result.Should().BeOfType <BadRequestObjectResult>();
            ((BadRequestObjectResult)result).Value.Should()
            .BeOfType <SerializableError>();
            sut.GoalMapper.DidNotReceive().Map(Arg.Any <GoalModel>());
            await sut.GoalService.DidNotReceive().UpdateAsync(Arg.Any <Goal>());
        }
コード例 #30
0
        public void TestSimple()
        {
            var model = new GoalModel ();

            var ag1 = new Agent ();
            var ag2 = new Agent ();
            var ag3 = new Agent ();
            var ag4 = new Agent ();

            var rootG = new Goal() { Name = "G" };
            model.Goals().Add (rootG);

            var G1 = new Goal() { Name = "G1" };
            var G2 = new Goal() { Name = "G2" };
            var G3 = new Goal() { Name = "G3" };
            var G4 = new Goal() { Name = "G4" };
            model.Goals().Add (G1);
            model.Goals().Add (G2);
            model.Goals().Add (G3);
            model.Goals().Add (G4);

            G1.AgentAssignments.Add (new AgentAssignment (ag1));
            G2.AgentAssignments.Add (new AgentAssignment (ag2));
            G3.AgentAssignments.Add (new AgentAssignment (ag3));
            G4.AgentAssignments.Add (new AgentAssignment (ag4));

            var alt1 = new AlternativeSystem () { Name = "Alt1" };
            var alt2 = new AlternativeSystem () { Name = "Alt2" };
            model.Systems.Add (alt1);
            model.Systems.Add (alt2);

            rootG.Refinements().Add (new GoalRefinement (G1, G2, G3) { SystemReference = alt1 });
            rootG.Refinements().Add (new GoalRefinement (G3, G4) { SystemReference = alt2 });

            var h = new AlternativeHelpers(); h.ComputeInAlternatives (model);

            Console.WriteLine ("G1: " + string.Join(", ", G1.InSystems.Select (x => x.Name)));
            Console.WriteLine ("G2: " + string.Join(", ", G2.InSystems.Select (x => x.Name)));
            Console.WriteLine ("G3: " + string.Join(", ", G3.InSystems.Select (x => x.Name)));
            Console.WriteLine ("G4: " + string.Join(", ", G4.InSystems.Select (x => x.Name)));

            G1.InSystems.ShallOnlyContain (new AlternativeSystem[] { alt1 });
            G2.InSystems.ShallOnlyContain (new AlternativeSystem[] { alt1 });
            G3.InSystems.ShallOnlyContain (new AlternativeSystem[] { alt1, alt2 });
            G4.InSystems.ShallOnlyContain (new AlternativeSystem[] { alt2 });
        }
コード例 #31
0
ファイル: GoalController.cs プロジェクト: akrojas07/budgetapp
        public async Task <IActionResult> UpsertGoals([FromBody] UpsertGoalsRequest upsertGoals)
        {
            try
            {
                if (upsertGoals == null || upsertGoals.UpsertGoals[0].GoalName == null)
                {
                    throw new ArgumentException("Bad Request");
                }

                List <GoalModel> coreGoals = new List <GoalModel>();

                foreach (var upsertGoal in upsertGoals.UpsertGoals)
                {
                    if (upsertGoal.UserId <= 0)
                    {
                        throw new Exception("User not found");
                    }
                    GoalModel coreGoal = new GoalModel()
                    {
                        Id           = upsertGoal.Id,
                        UserId       = upsertGoal.UserId,
                        Amount       = upsertGoal.GoalAmount,
                        TargetAmount = upsertGoal.TargetAmount,
                        GoalName     = upsertGoal.GoalName,
                        GoalSummary  = upsertGoal.GoalSummary,
                        StartDate    = upsertGoal.StartDate,
                        EndDate      = upsertGoal.EndDate
                    };

                    coreGoals.Add(coreGoal);
                }

                await _goalServices.UpsertGoalsService(coreGoals);

                return(Ok());
            }
            catch (ArgumentException ae)
            {
                return(StatusCode(400, ae.Message));
            }
            catch (Exception e)
            {
                return(StatusCode(500, e.Message));
            }
        }
コード例 #32
0
 public ProofObligationGenerator(GoalModel model, IEnumerable<Goal> goals, IEnumerable<Goal> obstructedGoals())