Exemple #1
0
        public async Task <bool> DeleteAsync(IChoiceModel choice)
        {
            var _choice = await _context.Choices.FindAsync(choice.ChoiceID);

            _context.Choices.Remove(_choice);
            return(true);
        }
Exemple #2
0
        public async Task <IChoiceModel> UpdateAsync(IChoiceModel choice)
        {
            var _choice = await _context.Choices.FindAsync(choice.ChoiceID);

            _context.Entry(_choice).CurrentValues.SetValues(_mapper.Map <IChoiceModel, Choice>(choice));
            return(choice);
        }
Exemple #3
0
        public async Task <IChoiceModel> LoadAlternativesPageAsync(IChoiceModel choice, int PageNumber, int PageSize = 5)
        {
            var _choice = await _context.Choices.FindAsync(choice.ChoiceID);

            await _context.Entry(_choice).Collection(c => c.Alternatives).Query().OrderBy(x => x.DateCreated).Skip((PageNumber - 1) * PageSize).Take(PageSize).LoadAsync();

            return(_mapper.Map <Choice, IChoiceModel>(_choice));;
        }
Exemple #4
0
        public async Task <bool> DeleteAsync(IChoiceModel choice)
        {
            bool b = true;

            b = await _choiceRepository.DeleteAsync(choice);

            await _choiceRepository.SaveAsync();

            return(b);
        }
Exemple #5
0
        public async Task <IChoiceModel> CreateAsync(IChoiceModel choice)
        {
            choice.ChoiceID    = Guid.NewGuid();
            choice.DateCreated = DateTime.Now;
            choice.DateUpdated = DateTime.Now;

            _choiceRepository.Add(choice);
            await _choiceRepository.SaveAsync();


            return(choice);
        }
Exemple #6
0
        public TChoiceModel Get<TChoiceModel>() where TChoiceModel : IChoiceModel {
            Type requestedType = typeof(TChoiceModel);
            IChoiceModel choiceModelObject = choiceModelObjectsDictionary.GetOrAdd(requestedType, (key) => {
                //create the Singleton of type (or derived type) of TChoiceModel
                Type possiblyCustomizedType = Global.Configuration.getAssignableObjectType(requestedType);
                choiceModelObject = (IChoiceModel)Activator.CreateInstance(possiblyCustomizedType);

                choiceModelObject.RunInitialize();
                Global.PrintFile.WriteLine("CustomizationDll Get<TChoiceModel> for '" + requestedType + "' just created object of type '" + possiblyCustomizedType);
                return choiceModelObject;
            });

            return (TChoiceModel)choiceModelObject;
        }   //end Get<TChoiceModel>
Exemple #7
0
        public async Task <IChoiceModel> UpdateAsync(IChoiceModel choice)
        {
            IChoiceModel updated;
            var          _baseChoice = await _choiceRepository.GetByIDAsync(choice.ChoiceID);

            if (choice.ChoiceName != null)
            {
                _baseChoice.ChoiceName = choice.ChoiceName;
            }
            _baseChoice.DateUpdated = DateTime.Now;

            updated = await _choiceRepository.UpdateAsync(_baseChoice);

            await _choiceRepository.SaveAsync();

            return(updated);
        }
Exemple #8
0
 public IChoiceModel Add(IChoiceModel choice)
 {
     _context.Choices.Add(_mapper.Map <IChoiceModel, Choice>(choice));
     return(choice);
 }