public void Add(PostMagazineViewModel magazineView) { Magazine magazine = Mapper.Map <PostMagazineViewModel, Magazine>(magazineView); magazine.PublicationType = PublicationType.Magazine; _magazineRepository.Add(magazine); }
public IHttpActionResult AddMagazineProduct(string name, int count, string localization) { using (var repository = new MagazineRepository()) { var entry = new MagazineEntry(); entry.Name = name; entry.Count = count; entry.Localization = localization; repository.Add(entry); } 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 bool AddMagazine(MagazineViewModel magazineViewModel) { try { Magazine magazine = Mapper.Map <MagazineViewModel, Magazine>(magazineViewModel); Save.AddItem(magazine, "../Magazines"); _magazineRepository.Add(magazine); return(true); } catch { return(false); } }
public void Add(PostMagazineViewModel magazineViewModel) { _magazineRepository.Add(ToMagazine(magazineViewModel)); }