public IHttpActionResult RemoveMagazineProduct(int id) { using (var repository = new MagazineRepository()) { if (repository.Remove(id) == false) { return(BadRequest()); } } return(Ok()); }
public IHttpActionResult Synchronize() { bool success = true; try { using (var repository = new MagazineRepository()) { var listOfMagazineEntries = repository.GetAll(); for (int i = 0; i < SERVICE_URLS.Length; i++) { IList <UnitEntry> list; try { var client = GetWebClient(SERVICE_URLS[i]); list = client.Unit.GetAllProducts(); } catch (HttpRequestException e) { Console.WriteLine("Cannot connect to the " + SERVICE_LOCATIONS[i] + "reason: " + e.ToString()); continue; } var entiresToRemove = listOfMagazineEntries.Where(x => x.Localization == SERVICE_LOCATIONS[i]); _log.InfoFormat("entiresToRemove"); foreach (var entry in entiresToRemove) { _log.InfoFormat($"{entry.Id.ToString()}"); repository.Remove(entry.Id); } foreach (var unitEntry in list) { MagazineEntry entry = new MagazineEntry(unitEntry.Name, unitEntry.Count.GetValueOrDefault(), SERVICE_LOCATIONS[i]); repository.Add(entry); } } synchronize = true; } } catch (System.Net.Http.HttpRequestException e) { success = false; synchronize = false; } if (success) { return(Ok()); } return(InternalServerError(new Exception("Cannot connect to unit webservice"))); }
public void Delete(int id) { _magazineRepository.Remove(id); }