Пример #1
0
 public IHttpActionResult RemoveMagazineProduct(int id)
 {
     using (var repository = new MagazineRepository())
     {
         if (repository.Remove(id) == false)
         {
             return(BadRequest());
         }
     }
     return(Ok());
 }
Пример #2
0
        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")));
        }
Пример #3
0
 public void Delete(int id)
 {
     _magazineRepository.Remove(id);
 }