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

            // would like to handle notfound in contexgt

            // Convert from DTO to internal model, now Entity
            // Will probably use Automapper

            Goals.API.Core.Entities.Goal goalEntity = new Core.Entities.Goal()
            {
                Id          = goal.Id,
                Name        = goal.Name,
                Description = goal.Description,
                TargetDate  = goal.TargetDate
            };

            try
            {
                await _repository.AddGoalAsync(goalEntity);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, $"Error posting goal, see Stack trace:  {ex.StackTrace}");
                throw ex;
            }
            return(NoContent());
        }
コード例 #2
0
        public IActionResult GetGoals(string Id)
        {
            try
            {
                var goalsList = _goalService.GetUserGoals(Id);
                if (goalsList.Count() < 1)
                {
                    return(NotFound());
                }

                var resultList = new List <GoalDTO>();
                // TODO add auto mapping
                foreach (var goal in goalsList)
                {
                    var goalDTO = new GoalDTO()
                    {
                        Id           = goal.ID,
                        GoalName     = goal.GoalName,
                        Type         = goal.Type,
                        Amount       = goal.TotalAmount,
                        CurAmount    = goal.CurrentAmount,
                        IsActive     = goal.IsActive,
                        UserId       = goal.UserID,
                        CompleteDate = goal.CompleteDate
                    };
                    resultList.Add(goalDTO);
                }
                return(Ok(resultList));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #3
0
        public async Task <IActionResult> Put(int id, [FromBody] GoalDTO goal)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != goal.Id)
            {
                return(BadRequest());
            }

            // would like to handle notfound in contexgt

            Goals.API.Core.Entities.Goal goalEntity = new Core.Entities.Goal()
            {
                Id          = goal.Id,
                Name        = goal.Name,
                Description = goal.Description,
                TargetDate  = goal.TargetDate
            };

            try
            {
                await _repository.UpdateGoalAsync(goalEntity);
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Error, $"Error putting Goal, see Stack Trace {ex.StackTrace}");

                throw ex;
            }
            return(NoContent());
        }
コード例 #4
0
 public AddMoneyPage(GoalDTO goal)
 {
     gop = new GoalProcessor();
     InitializeComponent();
     moneyReceived.Text = 0.ToString();
     goalToAdd          = goal;
 }
コード例 #5
0
        public async Task <IActionResult> PutGoal(long id, GoalDTO dtoGoal)
        {
            if (id != dtoGoal.Id || !GoalExists(id) || dtoGoal.Amount <= 0)
            {
                return(BadRequest());
            }

            var goal = await _context.Goal.FindAsync(id);

            goal.Update(dtoGoal);
            // Ado
            _adoContext.Update(goal);
            //End ado

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

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception)
            {
                throw;
            }

            return(NoContent());
        }
コード例 #6
0
        public async Task <ActionResult <GoalDTO> > PostGoal(GoalDTO goal)
        {
            goal.UserId = GetUserId();
            await goalRepository.SaveNewGoal(goal);

            return(CreatedAtAction("GetGoal", new { id = goal.Id }, goal));
        }
コード例 #7
0
        public async Task <ActionResult <Goal> > PostGoal(GoalDTO dtoGoal)
        {
            var goal = dtoGoal.ToEntity();

            try
            {
                var deadline = new DateTime(goal.Deadlinedate.Value.Ticks);

                if (goal.IsValid())
                {
                    return(BadRequest());
                }

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

                return(CreatedAtAction("GetGoal", new { id = goal.Id }, goal));
            }
            catch (InvalidOperationException)
            {
                dtoGoal.Deadlinedate = goal.Creationdate.AddMonths(1);

                return(await PostGoal(dtoGoal));
            }
            catch (Exception ex)
            {
                Log.Error(ex, ex.Message);
            }

            return(NoContent());
        }
コード例 #8
0
        public async Task <IHttpActionResult> PostGoal(Goal goal)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

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

            // New code:
            // Load author name
            db.Entry(goal).Reference(x => x.GamePlayer).Load();

            var dto = new GoalDTO()
            {
                Id                  = goal.Id,
                IsOwnGoal           = goal.IsOwnGoal,
                TimeScored          = goal.TimeScored,
                GamePlayerFirstName = goal.GamePlayer.FirstName,
                GamePlayerLastName  = goal.GamePlayer.LastName,
                TeamName            = goal.GamePlayer.Team.Name
            };

            return(CreatedAtRoute("DefaultApi", new { id = goal.Id }, goal));
        }
コード例 #9
0
        public ActionResult Create(/*List<GoalEntity> goalList, string gameId*/)
        {
            GoalDTO goals = new GoalDTO();



            return(PartialView("_EditAll", goals));
        }
コード例 #10
0
 public ModifyGoalPage(GoalDTO data)
 {
     InitializeComponent();
     modGoalName.Text      = data.Goalname;
     modMoneyRequired.Text = data.Moneyrequired.ToString();
     datePicker.Date       = data.Goalexpectedtime ?? default(DateTime);
     goalIds = data.Goalid;
 }
コード例 #11
0
 public IHttpActionResult Put(GoalDTO goalDTO)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest("Not a valid model"));
     }
     goalService.Put(goalDTO);
     return(Ok());
 }
コード例 #12
0
        public async Task <ActionResult <GoalDTO> > GetGoalById(int id)
        {
            GoalDTO goal = await goalRepository.GetGoalById(id);

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

            return(goal);
        }
コード例 #13
0
 public void Create(GoalDTO goalDTO)
 {
     using (var db = new ModelContext())
     {
         Goal goal = db.Goals.Create();
         goal.MatchId  = goalDTO.MatchId;
         goal.PlayerId = goalDTO.PlayerId;
         goal.TeamId   = goalDTO.TeamId;
         db.Goals.Add(goal);
         db.SaveChanges();
     }
 }
コード例 #14
0
 public Goal(GoalDTO source)
     : base(source)
 {
     GoalID         = source.GoalID;
     Name           = source.Name;
     Description    = source.Description;
     DomainID       = source.DomainID;
     IsCustom       = source.IsCustom;
     AutoAssign     = source.AutoAssign;
     OrganizationID = source.OrganizationID;
     IsPrison       = source.IsPrison;
 }
コード例 #15
0
        public static GoalEN Convert(GoalDTO dto)
        {
            GoalEN newinstance = null;

            try
            {
                if (dto != null)
                {
                    newinstance = new GoalEN();



                    if (dto.CarePlan_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.ICarePlanTemplateCAD carePlanTemplateCAD = new MoSIoTGenNHibernate.CAD.MosIoT.CarePlanTemplateCAD();

                        newinstance.CarePlan = carePlanTemplateCAD.ReadOIDDefault(dto.CarePlan_oid);
                    }
                    newinstance.Id       = dto.Id;
                    newinstance.Priority = dto.Priority;

                    if (dto.Targets != null)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.ITargetCAD targetCAD = new MoSIoTGenNHibernate.CAD.MosIoT.TargetCAD();

                        newinstance.Targets = new System.Collections.Generic.List <MoSIoTGenNHibernate.EN.MosIoT.TargetEN>();
                        foreach (TargetDTO entry in dto.Targets)
                        {
                            newinstance.Targets.Add(TargetAssemblerDTO.Convert(entry));
                        }
                    }
                    newinstance.Status = dto.Status;
                    if (dto.Condition_oid != -1)
                    {
                        MoSIoTGenNHibernate.CAD.MosIoT.IConditionCAD conditionCAD = new MoSIoTGenNHibernate.CAD.MosIoT.ConditionCAD();

                        newinstance.Condition = conditionCAD.ReadOIDDefault(dto.Condition_oid);
                    }
                    newinstance.Description = dto.Description;
                    newinstance.Category    = dto.Category;
                    newinstance.OutcomeCode = dto.OutcomeCode;
                    newinstance.Name        = dto.Name;
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(newinstance);
        }
コード例 #16
0
        //Add Goal
        public void AddGoal(GoalDTO goalDto, string userName)
        {
            var user = _repo.GetUserByUserName(userName);
            var goal = new Goal
            {
                Id      = goalDto.Id,
                Name    = goalDto.Name,
                Amount  = goalDto.Amount,
                Current = goalDto.Current,
                EndDate = goalDto.EndDate,
                UserId  = user.Id
            };

            _repo.Add(goal);
        }
コード例 #17
0
ファイル: GoalDTO.cs プロジェクト: gamific/gamific-web
        public override bool Equals(System.Object obj)
        {
            if (obj == null)
            {
                return(false);
            }

            GoalDTO other = obj as GoalDTO;

            if ((System.Object)other == null)
            {
                return(false);
            }

            return(other.GoalId == this.GoalId || other.MetricId == this.MetricId);
        }
コード例 #18
0
 public void Put(GoalDTO goalDTO)
 {
     using (var db = new ModelContext())
     {
         Goal existingGoal = db.Goals
                             .Where(m => m.Id == goalDTO.Id)
                             .FirstOrDefault();
         if (existingGoal != null)
         {
             existingGoal.TeamId   = goalDTO.TeamId;
             existingGoal.MatchId  = goalDTO.MatchId;
             existingGoal.PlayerId = goalDTO.PlayerId;
             db.SaveChanges();
         }
     }
 }
コード例 #19
0
        public ViewGoalPage(GoalDTO data)
        {
            InitializeComponent();
            goalId              = data.Goalid;
            gop                 = new GoalProcessor();
            goalName.Text       = data.Goalname;
            allocatedMoney.Text = data.Moneyallocated.ToString();
            requiredMoney.Text  = data.Moneyrequired.ToString();
            moneyLeft.Text      = (data.Moneyrequired - data.Moneyallocated).ToString();
            finishDay.Text      = data.Goalexpectedtime.ToString();
            DateTime expected = data.Goalexpectedtime ?? default(DateTime);

            daysLeft.Text            = (expected - DateTime.Now).Days.ToString();
            progressBar.Progress     = (1 / data.Moneyrequired * data.Moneyallocated);
            completeButton.IsEnabled = data.Moneyallocated == data.Moneyrequired;
        }
コード例 #20
0
        public GoalDTO GetGoalByMatch(int matchId, int id)
        {
            using (var db = new ModelContext())
            {
                List <Goal>    goals = db.Goals.Where(m => m.MatchId == matchId && m.Id == id).ToList();
                List <GoalDTO> dtos  = new List <GoalDTO>();

                foreach (var goal in goals)
                {
                    GoalDTO dto = new GoalDTO();
                    dto.Id       = goal.Id;
                    dto.MatchId  = goal.MatchId;
                    dto.PlayerId = goal.PlayerId;
                    dto.TeamId   = goal.TeamId;
                    dtos.Add(dto);
                }
                return(dtos.FirstOrDefault());
            }
        }
コード例 #21
0
        public List <GoalDTO> GetGoalsByPlayer(int playerId)
        {
            using (var db = new ModelContext())
            {
                List <Goal>    goals = db.Goals.Where(m => m.PlayerId == playerId).ToList();
                List <GoalDTO> dtos  = new List <GoalDTO>();

                foreach (var goal in goals)
                {
                    GoalDTO dto = new GoalDTO();
                    dto.Id       = goal.Id;
                    dto.MatchId  = goal.MatchId;
                    dto.PlayerId = goal.PlayerId;
                    dto.TeamId   = goal.TeamId;
                    dtos.Add(dto);
                }
                return(dtos);
            }
        }
コード例 #22
0
        public async Task <GoalDTO> SaveNewGoal(GoalDTO goal)
        {
            var newGoal = new Goal
            {
                Id          = goal.Id,
                Title       = goal.Title,
                UserId      = goal.UserId,
                StartDate   = goal.StartDate,
                EndDate     = goal.EndDate,
                StartValue  = goal.StartValue,
                TargetValue = goal.TargetValue,
                Category    = goal.Category,
                Completed   = goal.Completed,
            };

            _context.Goal.Add(newGoal);
            await _context.SaveChangesAsync();

            return(await GetGoalById(goal.Id));
        }
コード例 #23
0
        public AddOrEditGoalForm(EmotionalAppraisalAsset asset, GoalDTO goalDto)
        {
            InitializeComponent();
            ea = asset;

            //Validators
            textBoxGoalName.AllowNil       = false;
            textBoxGoalName.AllowUniversal = false;
            if (goalDto != null)
            {
                this.Text = "Edit Goal";
                buttonAddOrEditGoal.Text = "Update";
                goal = goalDto;
                textBoxGoalName.Value           = (Name)goalDto.Name;
                floatFieldBoxSignificance.Value = goalDto.Significance;
                floatFieldBoxLikelihood.Value   = goalDto.Likelihood;
            }
            else
            {
                goal = new GoalDTO();
                textBoxGoalName.Value = (Name)"g1";
            }
        }
コード例 #24
0
        public HttpResponseMessage New_([FromBody] GoalDTO dto)
        {
            // CAD, CEN, returnValue, returnOID
            GoalRESTCAD goalRESTCAD = null;
            GoalCEN     goalCEN     = null;
            GoalDTOA    returnValue = null;
            int         returnOID   = -1;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                goalRESTCAD = new GoalRESTCAD(session);
                goalCEN     = new GoalCEN(goalRESTCAD);

                // Create
                returnOID = goalCEN.New_(

                    //Atributo OID: p_carePlanTemplate
                    // attr.estaRelacionado: true
                    dto.CarePlanTemplate_oid                     // association role

                    , dto.Priority                               //Atributo Primitivo: p_priority
                    , dto.Status                                 //Atributo Primitivo: p_status
                    ,
                    //Atributo OID: p_condition
                    // attr.estaRelacionado: true
                    dto.Condition_oid                     // association role

                    , dto.Description                     //Atributo Primitivo: p_description
                    , dto.Category                        //Atributo Primitivo: p_category
                    , dto.OutcomeCode                     //Atributo Primitivo: p_outcomeCode
                    , dto.Name                            //Atributo Primitivo: p_name
                    );
                SessionCommit();

                // Convert return
                returnValue = GoalAssembler.Convert(goalRESTCAD.ReadOIDDefault(returnOID), session);
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 201 - Created
            response = this.Request.CreateResponse(HttpStatusCode.Created, returnValue);

            // Location Header

            /*
             * Dictionary<string, object> routeValues = new Dictionary<string, object>();
             *
             * // TODO: y rolPaths
             * routeValues.Add("id", returnOID);
             *
             * uri = Url.Link("GetOIDGoal", routeValues);
             * response.Headers.Location = new Uri(uri);
             */

            return(response);
        }
コード例 #25
0
        /*	if(hopeEmotion != null) {
         *              if(fearEmotion != null && fearEmotion.Intensity > hopeEmotion.Intensity) {
         *                      potential = fearEmotion.Potential;
         *                      finalEmotion = fearfullOutcome;
         *              }
         *              else {
         *                      potential = hopeEmotion.Potential;
         *                      finalEmotion = hopefullOutcome;
         *              }
         *      }
         *      else if(fearEmotion != null) {
         *              potential = fearEmotion.Potential;
         *              finalEmotion = fearfullOutcome;
         *      }
         *
         *      //The goal importance now affects 66% of the final potential value for the emotion
         *      potential = (potential +  2* goalImportance) / 3;
         *
         *      return new OCCBaseEmotion(finalEmotion, potential, evtId, eventName);
         * }*/


        /*
         *  private static OCCBaseEmotion AppraiseGoalEnd(OCCEmotionType hopefullOutcome, OCCEmotionType fearfullOutcome, IActiveEmotion hopeEmotion, IActiveEmotion fearEmotion, float goalImportance, uint evtId, Name eventName) {
         *
         *              OCCEmotionType finalEmotion;
         *              float potential = goalImportance;
         *              finalEmotion = hopefullOutcome;
         *
         *              if(hopeEmotion != null) {
         *                      if(fearEmotion != null && fearEmotion.Intensity > hopeEmotion.Intensity) {
         *                              potential = fearEmotion.Potential;
         *                              finalEmotion = fearfullOutcome;
         *                      }
         *                      else {
         *                              potential = hopeEmotion.Potential;
         *                              finalEmotion = hopefullOutcome;
         *                      }
         *              }
         *              else if(fearEmotion != null) {
         *                      potential = fearEmotion.Potential;
         *                      finalEmotion = fearfullOutcome;
         *              }
         *
         *              //The goal importance now affects 66% of the final potential value for the emotion
         *              potential = (potential +  2* goalImportance) / 3;
         *
         *              return new OCCBaseEmotion(finalEmotion, potential, evtId, eventName);
         *      }
         *
         * */
        ///// <summary>
        ///// Appraises a Goal's success according to the emotions that the agent is experiencing
        ///// </summary>
        ///// <param name="hopeEmotion">the emotion of Hope for achieving the goal that the character feels</param>
        ///// <param name="fearEmotion">the emotion of Fear for not achieving the goal that the character feels</param>
        ///// <param name="goalImportance">how important is the goal to the agent</param>
        ///// <param name="evt">The event that triggered the emotion</param>
        ///// <returns>the emotion created</returns>
        //private static OCCBaseEmotion AppraiseGoalSuccess(IActiveEmotion hopeEmotion, IActiveEmotion fearEmotion, float goalImportance, uint evt) {
        //	return AppraiseGoalEnd(OCCEmotionType.Satisfaction,OCCEmotionType.Relief,hopeEmotion,fearEmotion,goalImportance,evt);
        //}

        ///// <summary>
        ///// Appraises a Goal's Failure according to the emotions that the agent is experiencing
        ///// </summary>
        ///// <param name="hopeEmotion">the emotion of Hope for achieving the goal that the character feels</param>
        ///// <param name="fearEmotion">the emotion of Fear for not achieving the goal that the character feels</param>
        ///// <param name="goalImportance">how important is the goal to the agent</param>
        ///// <param name="evt">The event that triggered the emotion</param>
        ///// <returns></returns>
        //public static OCCBaseEmotion AppraiseGoalFailure(IActiveEmotion hopeEmotion, IActiveEmotion fearEmotion, float goalImportance, uint evt) {
        //	return AppraiseGoalEnd(OCCEmotionType.Disappointment,OCCEmotionType.FearsConfirmed,hopeEmotion,fearEmotion,goalImportance,evt);
        //}

        ///// <summary>
        ///// Appraises a Goal's likelihood of succeeding
        ///// </summary>
        ///// <param name="e">The event that triggered the emotion</param>
        ///// <param name="goalConduciveness">???????</param>
        ///// <param name="prob">probability of sucess</param>
        ///// <returns></returns>
        //	public static OCCBaseEmotion AppraiseGoalSuccessProbability(uint evt, float goalConduciveness, float prob) {
        //		return new OCCBaseEmotion(OCCEmotionType.Hope, prob * goalConduciveness, evt);
        //	}

        ///// <summary>
        ///// Appraises a Goal's likelihood of failure
        ///// </summary>
        ///// <param name="e">The event that triggered the emotion</param>
        ///// <param name="goalConduciveness">???????</param>
        ///// <param name="prob">probability of failure</param>
        ///// <returns></returns>
        //public static OCCBaseEmotion AppraiseGoalFailureProbability(uint evt, float goalConduciveness, float prob)
        //{
        //	return new OCCBaseEmotion(OCCEmotionType.Fear, prob * goalConduciveness, evt);
        //}

        public IEnumerable <IEmotion> AffectDerivation(EmotionalAppraisalAsset emotionalModule, IAppraisalFrame frame)
        {
            var evt = frame.AppraisedEvent;


            if (frame.ContainsAppraisalVariable(OCCAppraisalVariables.DESIRABILITY) && frame.ContainsAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS))
            {
                float desirability     = frame.GetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY);
                float praiseworthiness = frame.GetAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS);

                var composedEmotion = OCCAppraiseCompoundEmotions(evt, desirability, praiseworthiness);
                if (composedEmotion != null)
                {
                    yield return(composedEmotion);
                }
            }

            if (frame.ContainsAppraisalVariable(OCCAppraisalVariables.DESIRABILITY))
            {
                float desirability = frame.GetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY);
                if (desirability != 0)
                {
                    // yield return OCCAppraiseWellBeing(evt.Id, evt.EventName, desirability * 0.5f);
                    int counter = 0;
                    foreach (string variable in frame.AppraisalVariables.Where(v => v.StartsWith(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER)))
                    {
                        counter++;
                        string other = variable.Substring(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER.Length);
                        float  desirabilityForOther = frame.GetAppraisalVariable(variable);
                        if (desirabilityForOther != 0)
                        {
                            yield return(OCCAppraiseFortuneOfOthers(evt, desirability, desirabilityForOther, other));
                        }
                    }
                    if (counter == 0)
                    {
                        yield return(OCCAppraiseWellBeing(evt.Id, evt.EventName, desirability));
                    }
                }
            }



            foreach (string variable in frame.AppraisalVariables.Where(v => v.StartsWith(OCCAppraisalVariables.PRAISEWORTHINESS)))
            {
                float  praiseworthiness = frame.GetAppraisalVariable(variable);
                string other            = variable.Substring(OCCAppraisalVariables.PRAISEWORTHINESS.Length);
                if (other == null || other == " ")
                {
                    yield return(OCCAppraisePraiseworthiness(evt, praiseworthiness, "SELF"));
                }

                else
                {
                    yield return(OCCAppraisePraiseworthiness(evt, praiseworthiness, other));
                }
            }


            /*if(frame.ContainsAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS))
             * {
             *      float praiseworthiness = frame.GetAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS);
             *      if (praiseworthiness != 0)
             *              yield return OCCAppraisePraiseworthiness(evt, praiseworthiness, frame.Perspective);
             * }*/



            if (frame.ContainsAppraisalVariable(OCCAppraisalVariables.LIKE))
            {
                float like = frame.GetAppraisalVariable(OCCAppraisalVariables.LIKE);
                if (like != 0)
                {
                    yield return(OCCAppraiseAttribution(evt, like));
                }
            }

            foreach (string variable in frame.AppraisalVariables.Where(v => v.StartsWith(OCCAppraisalVariables.GOALSUCCESSPROBABILITY)))
            {
                float goalSuccessProbability = frame.GetAppraisalVariable(variable);

                string goalName = variable.Substring(OCCAppraisalVariables.GOALSUCCESSPROBABILITY.Length + 1);

                var goals = emotionalModule.GetAllGoals().ToList();


                GoalDTO g = goals.Find(x => goalName.ToString() == x.Name.ToString());

                if (g == null)
                {
                    continue;
                }

                var previousValue = g.Likelihood;

                g.Likelihood = goalSuccessProbability;


                yield return(AppraiseGoalSuccessProbability(evt, goalSuccessProbability, previousValue, g.Significance));
            }
        }
コード例 #26
0
        public EditMatchFormViewModel(IRegionManager regionManager, IRefereeService refereeService, IInteractionService interactionService, IGeocodingService geocodingService)
        {
            CalculateRouteCommand = new MyDelegateCommand(CalculateRoute);

            this.regionManager      = regionManager;
            this.refereeService     = refereeService;
            this.interactionService = interactionService;
            this.geocodingService   = geocodingService;

            AddGoalCommand = new DelegateCommand(() =>
            {
                var teamId = Match.HomeTeamPlayers.Contains(SelectedPlayer) ? (SelectedType == GoalType.Own ? Match.AwayTeamId : Match.HomeTeamId) :
                             (SelectedType == GoalType.Own ? Match.HomeTeamId : Match.AwayTeamId);
                var goal = new GoalDTO()
                {
                    Scorer   = SelectedPlayer,
                    GoalType = SelectedType,
                    TeamId   = teamId,
                    Time     = Time
                };
                if (teamId == Match.HomeTeamId)
                {
                    HomeGoals.Add(goal);
                    var ordered = this.HomeGoals.OrderBy(x => x.Time).ToList();
                    this.HomeGoals.Clear();
                    this.HomeGoals.AddRange(ordered);
                    Match.HomeTeamScore = (Match.HomeTeamScore ?? 0) + 1;
                }
                else
                {
                    AwayGoals.Add(goal);
                    var ordered = this.AwayGoals.OrderBy(x => x.Time).ToList();
                    this.AwayGoals.Clear();
                    this.AwayGoals.AddRange(ordered);
                    Match.AwayTeamScore = (Match.AwayTeamScore ?? 0) + 1;
                }
                this.interactionService.ShowMessageBox("Success", "Goal was added successfully");
            });

            RemoveGoalCommand = new DelegateCommand <GoalDTO>((goal) =>
            {
                if (HomeGoals.Contains(goal))
                {
                    HomeGoals.Remove(goal);
                    Match.HomeTeamScore--;
                }
                else
                {
                    AwayGoals.Remove(goal);
                    Match.AwayTeamScore--;
                }
            });

            OkCommand = new DelegateCommand(async() =>
            {
                if (IsEditing)
                {
                    IsEnabled           = true;
                    Match.HomeTeamGoals = HomeGoals.ToArray();
                    Match.AwayTeamGoals = AwayGoals.ToArray();
                    if (Match.HomeTeamScore == null)
                    {
                        Match.HomeTeamScore = 0;
                    }
                    if (Match.AwayTeamScore == null)
                    {
                        Match.AwayTeamScore = 0;
                    }
                    await this.refereeService.SaveGoalsAsync(Match);
                    IsEnabled = false;
                }
                GlobalCommands.GoBackCommand.Execute(null);
            });
        }
コード例 #27
0
 public Goal(GoalDTO goalDto)
 {
     this.Name         = (Name)goalDto.Name;
     this.Significance = goalDto.Significance;
     this.Likelihood   = goalDto.Likelihood;
 }
コード例 #28
0
ファイル: GoalsController.cs プロジェクト: mttkrb/BudgetBook
 public void Post([FromBody] GoalDTO goalDto)
 {
     _service.AddGoal(goalDto, User.Identity.Name);
 }
コード例 #29
0
 public void AddOrUpdateGoal(GoalDTO goal)
 {
     m_goals[goal.Name] = new Goal(goal);
 }
コード例 #30
0
        public HttpResponseMessage Modify(int idGoal, [FromBody] GoalDTO dto)
        {
            // CAD, CEN, returnValue
            GoalRESTCAD goalRESTCAD = null;
            GoalCEN     goalCEN     = null;
            GoalDTOA    returnValue = null;

            // HTTP response
            HttpResponseMessage response = null;
            string uri = null;

            try
            {
                SessionInitializeTransaction();


                goalRESTCAD = new GoalRESTCAD(session);
                goalCEN     = new GoalCEN(goalRESTCAD);

                // Modify
                goalCEN.Modify(idGoal,
                               dto.Priority
                               ,
                               dto.Status
                               ,
                               dto.Description
                               ,
                               dto.Category
                               ,
                               dto.OutcomeCode
                               ,
                               dto.Name
                               );

                // Return modified object
                returnValue = GoalAssembler.Convert(goalRESTCAD.ReadOIDDefault(idGoal), session);

                SessionCommit();
            }

            catch (Exception e)
            {
                SessionRollBack();

                if (e.GetType() == typeof(HttpResponseException))
                {
                    throw e;
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) && e.Message.Equals("El token es incorrecto"))
                {
                    throw new HttpResponseException(HttpStatusCode.Forbidden);
                }
                else if (e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.ModelException) || e.GetType() == typeof(MoSIoTGenNHibernate.Exceptions.DataLayerException))
                {
                    throw new HttpResponseException(HttpStatusCode.BadRequest);
                }
                else
                {
                    throw new HttpResponseException(HttpStatusCode.InternalServerError);
                }
            }
            finally
            {
                SessionClose();
            }

            // Return 404 - Not found
            if (returnValue == null)
            {
                return(this.Request.CreateResponse(HttpStatusCode.NotFound));
            }
            // Return 200 - OK
            else
            {
                response = this.Request.CreateResponse(HttpStatusCode.OK, returnValue);

                return(response);
            }
        }