Example #1
0
 public async Task <TacheReadDto> Ajouter(TacheCreateDto tache)
 {
     try
     {
         return(await ApiController.Post <TacheCreateDto, TacheReadDto>(tache));
     }
     catch (Exception ex)
     {
         throw new Exception("Impossible d'ajouter la tâche " + tache.Nom + "  : \n" + ex.Message);
     }
 }
Example #2
0
        public ActionResult <TacheReadDto> Create(TacheCreateDto tacheCreateDto)
        {
            Tache tache = _mapper.Map <Tache>(tacheCreateDto); // trouve le model à utiliser

            _repository.Create(tache);                         // crée la command en ram
            _repository.SaveChanges();                         // sauvegarde les changements dans la bdd

            TacheReadDto tacheReadDto = _mapper.Map <TacheReadDto>(tache);

            tacheReadDto.Locataire = InstanceLocataire.GetById(tacheReadDto.LocataireId);

            //return CreatedAtRoute(nameof(GetById), new { Id = commandReadDto.Id }, commandReadDto);
            return(Ok(tacheReadDto));
        }
Example #3
0
        private async Task Ajouter(string name, DateTime datteDebut, int cycle, List <int> idLocataires)
        {
            // Crée la tâche
            TacheReadDto tache = new TacheReadDto()
            {
                Nom         = name,
                DateFin     = datteDebut,
                Active      = true,
                LocataireId = idLocataires[0],
                Cycle       = cycle
            };

            // validation des données
            ValidationResult result = new TacheValidator().Validate(tache);

            if (!result.IsValid)
            {
                Dialog.Show($"{result.Errors[0].PropertyName} : {result.Errors[0].ErrorMessage}");
                return;
            }

            TacheCreateDto tacheCreateDto = TachesProfile.ReadToCreate().Map <TacheCreateDto>(tache);

            // Ajout de la tâche à la bdd
            int idTache = (await _repositoryTaches.Ajouter(tacheCreateDto)).Id;

            // Ajout les locataires à la tâche dans la bdd (table liaison)
            foreach (int idSelected in idLocataires)
            {
                await _liaison.Ajouter(
                    idSelected,
                    idTache
                    );
            }

            Dialog.Show("La tâche " + name + " a bien été ajoutée");
        }
Example #4
0
 /**
  * <summary>Permet de créer une tâche</summary>
  * <param name="tache">Données de la tâche à créer du type <see cref="TacheCreateDto"/></param>
  * <returns>Renvoie la tâche créée en <see cref="TacheReadDto"/></returns>
  */
 public async Task <TacheReadDto> PostAsync(TacheCreateDto tache)
 {
     return(await _tachesApi.Post <TacheCreateDto, TacheReadDto>(tache));
 }