예제 #1
0
        /// <summary>
        /// Создание задачи
        /// </summary>
        /// <param name="objectiveModel">Модель задачи</param>
        /// <returns>Новый элемент меню</returns>
        public async Task <MenuItemModel> Create(ObjectiveModel objectiveModel)
        {
            var entity = _mapper.Map <ObjectiveEntity>(objectiveModel);

            if (objectiveModel.ParentId == null || objectiveModel.ParentId == Guid.Empty)
            {
                await _dbRepository.AddAsync(entity);
            }
            else
            {
                var parentEntity = _dbRepository
                                   .Get <ObjectiveEntity>(x => x.Id == objectiveModel.ParentId)
                                   .Include(x => x.SubObjectives).FirstOrDefault();

                if (parentEntity == null)
                {
                    return(null);
                }

                parentEntity.SubObjectives.Add(entity);
            }
            await _dbRepository.SaveChangesAsync();

            var menuItem = _mapper.Map <MenuItemModel>(entity);

            return(menuItem);
        }
예제 #2
0
    public void AddObjective(int objectiveID, float time, bool sound = true)
    {
        if (!CheckObjective(objectiveID))
        {
            ObjectiveModel objModel = objectives.SingleOrDefault(o => o.identifier == objectiveID);

            if (!objModel.isCompleted)
            {
                GameObject obj = Instantiate(ObjectivePrefab, ObjectivesUI.transform);
                obj.transform.GetChild(0).GetComponent <Text>().text = objModel.objectiveText;
                objModel.objective = obj;

                objectiveCache.Add(objModel);

                string text = objModel.objectiveText;

                if (text.Count(ch => ch == '{') > 1 && text.Count(ch => ch == '}') > 1)
                {
                    text = string.Format(text, objModel.completion, objModel.toComplete);
                }

                PushObjectiveText(text, time, isUppercased);

                if (sound)
                {
                    PlaySound(newObjective);
                }
            }
        }
    }
예제 #3
0
 public ObjectiveThingsModel GetObjectiveThingsModel(string id, ObjectiveModel om)
 {
     foreach(ObjectiveThingsModel otm in om.Objects) {
         //found
         if (String.Equals(otm.Id, id)) {
             return otm;
         }
     }
     //not found
     return null;
 }
예제 #4
0
        public List <ObjectiveModel> GetAllObjective()
        {
            List <ObjectiveModel>  lom = new List <ObjectiveModel>();
            List <ObjectiveEntity> loe = _objectiveRepository.Get();

            foreach (ObjectiveEntity item in loe)
            {
                ObjectiveModel om = new ObjectiveModel();
                om.IdObjective = item.IdObjective;
                om.Objective   = item.Objective;
                lom.Add(om);
            }
            return(lom);
        }
        public async Task <ActionResult> Update([FromBody] ObjectiveModel model)
        {
            if (!ModelState.IsValid)
            {
                throw new ValidationException("Form validation error");
            }
            var result = await _objectiveService.Update(model);

            if (result == Guid.Empty)
            {
                throw new ObjectiveNotFoundException("Objective not found for update.");
            }
            return(Ok(result));
        }
        public async Task <ActionResult <MenuItemModel> > Create([FromBody] ObjectiveModel objectiveModel)
        {
            if (!ModelState.IsValid)
            {
                throw new ValidationException("Form validation error");
            }
            var result = await _objectiveService.Create(objectiveModel);

            if (result == null)
            {
                throw new ObjectiveNotFoundException("Cant create objective, parent not found.");
            }
            return(Ok(result));
        }
        public int Save(ObjectiveModel model)
        {
            SqlObject.CommandText = StoredProcedures.Objectives.SaveObjective;
            int IsActive = model.IsActive.Equals("true") ? 1 : 0;

            SqlObject.Parameters = new object[]
            {
                model.ObjectiveID,
                model.TopicID,
                model.ObjectiveName,
                model.ObjectiveDescription,
                IsActive
            };
            return(_repository.Save());
        }
예제 #8
0
        private async Task <ObjectiveProgressModel> ByObjectiveModel(ObjectiveModel objectiveModel, List <UserLessonsModel> finishedLessons)
        {
            var objectiveProgressModel = mapper.Map <ObjectiveProgressModel>(objectiveModel);
            var condition  = Convert.ToInt32(objectiveProgressModel.Condition);
            var isAchieved = false;

            switch (objectiveModel.ObjectiveType)
            {
            case Database.Enums.ObjectiveType.LessonCount:
                // The condition here is the number of finished lessons needed to achieve the objective
                isAchieved = condition <= finishedLessons.Count;
                objectiveProgressModel.Progress    = isAchieved ? condition : finishedLessons.Count;
                objectiveProgressModel.IsCompleted = isAchieved;

                break;

            case Database.Enums.ObjectiveType.ChapterCount:

                var finishedChaptersCount = (await GetFinishedChaptersByLessons(finishedLessons)).Count();
                // The condition here is the number of finished courses needed to achieve the objective
                isAchieved = condition <= finishedChaptersCount;
                objectiveProgressModel.Progress    = isAchieved ? condition : finishedChaptersCount;
                objectiveProgressModel.IsCompleted = isAchieved;

                break;

            case Database.Enums.ObjectiveType.SpecificCourse:
                // The condition here is the ID of the course we check against
                var courses = await coursesService.GetByIdAsync(condition);

                var finishedChapters = await GetFinishedChaptersByLessons(finishedLessons);

                if (courses.Chapters != null && courses.Chapters.Count > 0)
                {
                    isAchieved = courses.Chapters.Select(s => s.Id).Intersect(finishedChapters.Select(s => s.Id)).Count() == courses.Chapters.Count();
                }

                objectiveProgressModel.Progress    = isAchieved ? 1 : 0;
                objectiveProgressModel.IsCompleted = isAchieved;

                break;

            default:
                throw new ArgumentException($"Unknown objective type: {objectiveModel.ObjectiveType.ToString()}");
            }

            return(objectiveProgressModel);
        }
예제 #9
0
        public async Task <IActionResult> Update([FromRoute] Guid id, [FromBody] ObjectiveModel model)
        {
            try
            {
                var response = await _service.Update(model);

                if (!response.IsSuccessful)
                {
                    return(BadRequest(response));
                }
                return(Ok(response));
            }
            catch
            {
                return(StatusCode(500, "Internal Server Error."));
            }
        }
예제 #10
0
    public void AddObjectiveModel(ObjectiveModel model)
    {
        ObjectiveModel objModel = new ObjectiveModel(model.identifier, model.toComplete, model.isCompleted);
        ObjectiveModel original = objectives[objModel.identifier];

        objModel.objectiveText = original.objectiveText;
        objModel.toComplete    = original.toComplete;
        objModel.completion    = original.completion;

        if (!objModel.isCompleted)
        {
            GameObject objObject = Instantiate(ObjectivePrefab, ObjectivesUI.transform);
            objObject.transform.GetChild(0).GetComponent <Text>().text = objModel.objectiveText;
            objModel.objective = objObject;
            objectiveCache.Add(objModel);
        }
    }
예제 #11
0
        /// <summary>
        /// Обновление задачи
        /// </summary>
        /// <param name="objectiveModel">Модель задачи</param>
        /// <returns>ИД обновленной задачи</returns>
        public async Task <Guid> Update(ObjectiveModel objectiveModel)
        {
            var entityForUpdate = _dbRepository
                                  .Get <ObjectiveEntity>()
                                  .FirstOrDefault(x => x.Id == objectiveModel.Id);

            if (entityForUpdate == null)
            {
                return(Guid.Empty);
            }

            if (objectiveModel.ObjectiveStatus == ObjectiveStatusType.Completed)
            {
                var now = DateTime.Now;
                objectiveModel.CompletedTime = now.ToString("f");
                var createdTime = entityForUpdate.CreatedTime;
                objectiveModel.FactTime = (int)now.Subtract(createdTime).TotalHours;
            }
            _mapper.Map(objectiveModel, entityForUpdate);
            await _dbRepository.SaveChangesAsync();

            return(entityForUpdate.Id);
        }
예제 #12
0
 public int SaveObjective(ObjectiveModel SModel)
 {
     return(_coreModel.Save(SModel));
     //return new string[] { "value1", "value2" };
 }
예제 #13
0
 private int CalculateFactTime(ObjectiveModel data)
 {
     return(data.FactTime + data.SubObjectives.Sum(CalculateFactTime));
 }
예제 #14
0
 //ToDo Подумать как избавиться от приватных методов.
 private int CalculateEstimateTime(ObjectiveModel data)
 {
     return(data.EstimateTime + data.SubObjectives.Sum(CalculateEstimateTime));
 }