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); } }
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)); }
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"); }
/** * <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)); }