public async Task <ResultDTO> EditDeveloper([FromBody] DeveloperDTO developer) { if (_context.Developers.FirstOrDefault(x => x.Id == developer.Id) != null) { _context.Developers.FirstOrDefault(x => x.Id == developer.Id).Name = developer.Name; await _context.SaveChangesAsync(); return(new ResultDTO { Status = 200, Message = "Item changed" }); } else { return(new ResultErrorDTO { Status = 600, Message = "Error", Errors = new List <string> { "Error on Server" } }); } }
//Update public bool UpdateDevApp(string devId, string appName, DevApp devApp) { try { DeveloperDTO dev = GetDeveloperById(devId); DevApp da = _unitOfWork.AppRepository.GetWithInclude().Where(d => d.DevId == dev.DevId).Where(d => d.AppName.Equals(appName)).FirstOrDefault(); if (da != null) { //Prevent user from changing app id and foreign key while updating devApp.DevId = da.DevId; devApp.AppId = da.AppId; _unitOfWork.AppRepository.Update(devApp); foreach (AppEntity appEntity in devApp.AppEntitiys) { _unitOfWork.EntityRepository.Update(appEntity); foreach (EntityField entityField in appEntity.EntityFields) { _unitOfWork.FieldRepository.Update(entityField); } } _unitOfWork.Save(); return(true); } return(false); } catch (Exception e) { throw e; } }
public DeveloperDTO GetById(int id) { DeveloperDTO retour = new DeveloperDTO(); retour = _logic.GetById(id); return(retour); }
public DeveloperDTO GetById(int Id) { DeveloperDTO retour = new DeveloperDTO(); Developer objet = _repo.Get(Id); retour = MapDeveloperDTO.ToDto(objet); return(retour); }
public DeveloperDTO Update(DeveloperDTO objet) { Developer entity = MapDeveloper.ToEntity(objet, false); Developer resultat = _repo.Update(entity); DeveloperDTO retour = MapDeveloperDTO.ToDto(resultat); return(retour); }
public DeveloperDTO Create(DeveloperDTO objet) { Developer entite = MapDeveloper.ToEntity(objet, true); Developer resultat = _repo.Create(entite); objet = MapDeveloperDTO.ToDto(resultat); return(objet); }
public DeveloperDialog(string telegramId, string telegramName) { developerDTO = new DeveloperDTO { TelegramId = telegramId, TelegramNickname = telegramName }; }
public async Task <Developer> UpdateDeveloper(long id, DeveloperDTO developer) { var updatedDeveloper = await GetDeveloperById(id); updatedDeveloper.Name = developer.Name; updatedDeveloper.EstablishmentYear = developer.EstablishmentYear; var result = _context.Developers.Update(updatedDeveloper); await _context.SaveChangesAsync(); return(result.Entity); }
public async Task <IActionResult> AddDeveloper([FromBody] DeveloperDTO developer) { try { return(Ok(await _developersRepository.AddDeveloper(developer))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> UpdateDeveloperInfo(long id, [FromBody] DeveloperDTO developer) { try { return(Ok(await _developersRepository.UpdateDeveloper(id, developer))); } catch (Exception e) { return(NotFound(e.Message)); } }
public DeveloperDTO EditGetDeveloper([FromRoute] int id) { var devdb = _context.Developers.FirstOrDefault(x => x.Id == id); var dev = new DeveloperDTO(); dev.Id = devdb.Id; dev.Name = devdb.Name; return(dev); }
public IHttpActionResult GetRegisteredUser([FromUri] string id) { DeveloperDTO dto = _developerService.GetDeveloperById(id); if (dto != null) { return(Ok(dto)); } else { return(NotFound()); } }
public async Task <long> AddDeveloper(DeveloperDTO developer) { var developerEntity = new Developer() { Name = developer.Name, EstablishmentYear = developer.EstablishmentYear }; var result = await _context.AddAsync <Developer>(developerEntity); await _context.SaveChangesAsync(); return(result.Entity.ID); }
public bool Insert(DeveloperDTO dto) { if (!dto.IsValid()) { return(false); } var entity = new Developer(dto.Name, null); _developerRepository.Insert(entity); return(true); }
internal static DeveloperDTO ToDto(Developer objet) { DeveloperDTO retour = new DeveloperDTO(); if (objet != null) { retour.Id = objet.Id; retour.LastName = objet.LastName; retour.FirstName = objet.FirstName; retour.IsDeleted = objet.IsDeleted; retour.DateCreation = (System.DateTime)objet.DateCreation; retour.DateModification = (System.DateTime)objet.DateModification; } return(retour); }
public bool Update(DeveloperDTO dto, int id) { if (!dto.IsValid()) { return(false); } var data = _developerRepository.Get(id); data.SetName(dto.Name); _developerRepository.Update(data); return(true); }
//Create public DevAppDTO InsertDevApp(string devId, DevApp devApp) { DevAppDTO dto = new DevAppDTO(); try { DeveloperDTO devDTO = GetDeveloperById(devId); devApp.DevId = devDTO.DevId; dto = _unitOfWork.AppRepository.Insert(devApp); _unitOfWork.Save(); } catch (Exception ex) { throw ex; } return(dto); }
//Create public DeveloperDTO InsertDev(Developer dev) { DeveloperDTO dto = new DeveloperDTO(); try { //using (var scope = new TransactionScope()) dto = _unitOfWork.DeveloperRepository.Insert(dev); _unitOfWork.Save(); // scope.complete(); } catch (Exception ex) { throw ex; } return(dto); }
//Activate public bool SetDevAppActive(string devId, string appName, bool val) { DeveloperDTO dev = GetDeveloperById(devId); DevApp da = _unitOfWork.AppRepository.GetWithInclude().Where(d => d.DevId == dev.DevId).Where(d => d.AppName.Equals(appName)).FirstOrDefault(); if (da != null) { da.DeactivationFlag = val; _unitOfWork.AppRepository.Update(da); _unitOfWork.Save(); return(true); } else { return(false); } }
//Delete public DeveloperDTO DeleteDeveloper(string id) { DeveloperDTO dto = new DeveloperDTO(); try { Developer developer = _unitOfWork.DeveloperRepository.GetWithInclude().Where(d => d.UserId.Equals(id)).FirstOrDefault(); if (developer != null) { dto = _unitOfWork.DeveloperRepository.Delete(developer); _unitOfWork.Save(); } } catch (Exception ex) { throw ex; } return(dto); }
//Read public override DeveloperDTO GetDeveloperById(string id) { DeveloperDTO dto = new DeveloperDTO(); try { dto = _unitOfWork.DeveloperRepository.GetWithInclude() .Include(d => d.DevApps).Where(d => d.DeactivationFlag.Equals(false)) .Include(d => d.DevApps.Select(o => o.AppEntitiys)) .Include(d => d.DevApps.Select(o => o.AppEntitiys.Select(e => e.EntityFields))) .Where(d => d.UserId.Equals(id)).FirstOrDefault(); } catch (Exception ex) { throw ex; } return(dto); }
public ActionResult Save(DeveloperDTO developerDTO) { try { if (_developerService.Insert(developerDTO)) { return(Ok("Salvo com sucesso")); } else { return(BadRequest("Nao foi possivel salvar o desenvolvedor. Por favor, verifique os campos.")); } } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult Edit(DeveloperDTO developerDTO, int id) { try { if (_developerService.Update(developerDTO, id)) { return(Ok("Atualizado com Sucesso")); } else { return(BadRequest("Nao foi possivel salvar o desenvolvedor. Por favor, verifique os campos.")); } } catch (Exception ex) { throw ex; } }
//Read public override DevAppDTO GetDevAppById(string devId, string appName) { DevAppDTO dto = new DevAppDTO(); try { DeveloperDTO dev = GetDeveloperById(devId); if (dev != null) { return(_unitOfWork.AppRepository.GetWithInclude().Include(d => d.AppEntitiys).Where(d => d.DeactivationFlag.Equals(false)).Where(d => d.DevId == dev.DevId) .Include(d => d.AppEntitiys.Select(o => o.EntityFields)).Where(d => d.AppName.Equals(appName)).FirstOrDefault()); } return(null); } catch (Exception ex) { throw ex; } }
//modification d'entité avec fourniture de l'Id obligatoire public ActionResult <DeveloperDTO> Put([FromBody] DeveloperDTO objet) { if (ModelState.IsValid && objet.Id.HasValue) { try { DeveloperDTO resultat = _logic.Update(objet); return(resultat); } catch { return(null); } } else { return(BadRequest("DeveloperDTO invalide")); } }
//Delete public DevAppDTO DeleteDevApp(string devId, string appName) { DeveloperDTO dev = GetDeveloperById(devId); try { DevApp devApp = _unitOfWork.AppRepository.GetWithInclude().Where(d => d.DevId == dev.DevId).Where(d => d.AppName.Equals(appName)).FirstOrDefault(); if (devApp != null) { DevAppDTO dto = _unitOfWork.AppRepository.Delete(devApp); _unitOfWork.Save(); return(dto); } return(null); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> GetDeveloper([FromRoute] int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var developer = await _context.Developer.Include(dv => dv.VideoGames).FirstAsync(dv => dv.DevId == id); if (developer == null) { return(NotFound()); } DeveloperDTO dto = new DeveloperDTO() { DevID = developer.DevId, Name = developer.Name, VideoGames = new List <VideoGamesDTO>() }; foreach (VideoGames vg in developer.VideoGames) { VideoGamesDTO vgdto = new VideoGamesDTO() { VideoGamesID = vg.Id, Title = vg.Title, System = vg.System, ReleaseDate = vg.ReleaseDate, ESRB = vg.Esrb, Publisher = vg.Publisher, Developer = vg.Developer }; dto.VideoGames.Add(vgdto); } return(Ok(dto)); }
internal static Developer ToEntity(DeveloperDTO objet, bool creation) { Developer retour = new Developer(); if (objet != null) { retour.LastName = objet.LastName; retour.FirstName = objet.FirstName; if (creation) { retour.DateCreation = DateTime.UtcNow; retour.DateModification = DateTime.UtcNow; retour.IsDeleted = false; } else { retour.Id = objet.Id; retour.DateCreation = objet.DateCreation; retour.DateModification = DateTime.UtcNow; retour.IsDeleted = objet.IsDeleted; } } return(retour); }
public IEnumerable <DeveloperDTO> GetDeveloper() { List <Developer> developers = _context.Developer.Include(dv => dv.VideoGames).ToList(); List <DeveloperDTO> developerDTOList = new List <DeveloperDTO>(); foreach (Developer dv in developers) { List <VideoGamesDTO> videogamesDTOList = new List <VideoGamesDTO>(); foreach (VideoGames vg in dv.VideoGames) { VideoGamesDTO vgDTO = new VideoGamesDTO() { VideoGamesID = vg.Id, Title = vg.Title, System = vg.System, ReleaseDate = vg.ReleaseDate, ESRB = vg.Esrb, Publisher = vg.Publisher, Developer = vg.Developer }; videogamesDTOList.Add(vgDTO); } DeveloperDTO dvdto = new DeveloperDTO() { DevID = dv.DevId, Name = dv.Name }; developerDTOList.Add(dvdto); } return(developerDTOList); }
public IHttpActionResult RegisterUser([FromBody] Developer developer) { DeveloperDTO dto = _developerService.InsertDev(developer); return(Created(new Uri(Url.Link(Constants.GET_DEVELOPER_BY_ID, new { id = developer.UserId })), dto)); }