public IActionResult CreateArticlePartial(int format = 0, int year = 0, int section = 0) { var magazineCategory = new MagazineCategory(); magazineCategory.Id = format; var magazine = new Magazine(); magazine.Category = magazineCategory; magazine.PublishYear = year; magazine.PublishSection = String.Format("{0}", section); var model = new Article(); model.Magazine = magazine; var tags = _magService.GetAllTags(); if (!tags.IsOk()) { return(PartialView("Layout/_ErrorHandling", string.Format("Hiba a lekérés során ({0} : {1})", tags.Status, tags.Message))); } var authors = _magService.GetAllAuthors(); if (!authors.IsOk()) { return(PartialView("Layout/_ErrorHandling", string.Format("Hiba a lekérés során ({0} : {1})", authors.Status, authors.Message))); } var mapper = _mapper.Map <ArticleVM>(model).Map(tags.Data).Map(authors.Data); // Only grid string query values will be visible here. return(PartialView("Partials/_AddArticle", mapper)); }
public async Task <IActionResult> CreateCategory(MagazineCategoryVM model) { if (string.IsNullOrEmpty(LoggedInName()) || !IsAllowed(UserLevel.AccessArea.MagazineAdmin)) { return(RedirectToAction("Login", "User")); } if (!ModelState.IsValid) { return(RedirectToAction("CreateCategory")); } var result = await SaveMagazineImage(model.IconImage, CategoryIconFolder); var newCategory = new MagazineCategory() { Name = model.Name, CategoryId = _rnd.Next(1001, 9999).ToString(), Order = model.Order, IconImage = model.IconImage.FileName }; if (_magazineCategories == null) { _magazineCategories = await GetListOfCategories(); } _magazineCategories.Add(newCategory); _cacheManager.Set(CategoryCacheKey, _magazineCategories); return(RedirectToAction("CreateCategory")); }
public ActionResult Create(MagazineCategory magazineCategoryEntity) { BlueprintMediaServisEntity entities = new BlueprintMediaServisEntity(); var categoryNamesThatEqualNew = entities.MagazineCategory.Where(w => w.text == magazineCategoryEntity.text); if (magazineCategoryEntity.text == null) { Session["status"] = "error"; return(RedirectToAction("Index")); } if (magazineCategoryEntity.text.Length < 3) { Session["status"] = "error"; return(RedirectToAction("Index")); } if (categoryNamesThatEqualNew.Count() != 0) { Session["status"] = "foundEqual"; } else { entities.MagazineCategory.Add(magazineCategoryEntity); entities.SaveChanges(); Session["status"] = "success"; } return(RedirectToAction("Index")); }
public ActionResult Update(MagazineCategory magazineCategory) { BlueprintMediaServisEntity entity = new BlueprintMediaServisEntity(); var categoryNamesThatEqualNew = entity.MagazineCategory.Where(w => w.text == magazineCategory.text); var magazineCategoryTheUpdate = entity.MagazineCategory.Where(w => w.id == magazineCategory.id).FirstOrDefault(); if (categoryNamesThatEqualNew.Count() == 0) { magazineCategoryTheUpdate.text = magazineCategory.text; entity.SaveChanges(); Session["Status"] = "success"; return(RedirectToAction("Index")); } else if (categoryNamesThatEqualNew.Count() == 1 && categoryNamesThatEqualNew.First().text == magazineCategoryTheUpdate.text) { Session["Status"] = "noChange"; return(RedirectToAction("Index")); } else { Session["Status"] = "failed"; return(RedirectToAction("Index")); } }
public ActionResult Index() { BlueprintMediaServisEntity BMSentity = new BlueprintMediaServisEntity(); MagazineCategory magazineCategoryEntity = new MagazineCategory(); IEnumerable <SelectListItem> enumarableMagazineCategoryList = magazineCategoryEntity.RetrieveMagazineCategory(); ViewBag.Status = Session["status"]; Session["status"] = null; return(View(Tuple.Create <Magazines, IEnumerable <Magazines>, MagazinesContent, IEnumerable <SelectListItem> >(new Magazines(), BMSentity.Magazines.ToList(), new MagazinesContent(), enumarableMagazineCategoryList))); }
public IHttpActionResult GetMagazineCategory(int id) { MagazineCategory magazineCategory = db.MagazineCategory.Find(id); if (magazineCategory == null) { return(NotFound()); } return(Ok(magazineCategory)); }
public ActionResult Index() { BlueprintMediaServisEntity BMSentity = new BlueprintMediaServisEntity(); MagazineCategory magazineCategoryEntity = new MagazineCategory(); IEnumerable <SelectListItem> enumarableMagazineCategoryList = magazineCategoryEntity.RetrieveMagazineCategory(); var query = BMSentity.MagazinesContent.ToList(); var result = query.Where(m => m.id == (int)Session["id"]).ToList(); ViewData["category"] = result[0].categoryId; return(View(Tuple.Create <MagazinesContent, IEnumerable <SelectListItem>, IEnumerable <MagazinesContent> >(new MagazinesContent(), enumarableMagazineCategoryList, result))); }
public IActionResult AddMagazineCategory(MagazineCategory model) { if (!ModelState.IsValid) { TempData["ErrorMessage"] = string.Format("Hiba a validáció során! Kérem töltsön ki minden szükséges mezőt!"); return(RedirectToAction("MagazineList")); } var magazines = _magCatService.Add(model); if (magazines.IsOk()) { return(RedirectToAction("MagazineList")); } TempData["ErrorMessage"] = string.Format("Hiba a hozzáadás során ({0} : {1})", magazines.Status, magazines.Message); return(RedirectToAction("MagazineList")); }
public Result <MagazineCategory> Add(MagazineCategory model) { try { var exists = _unitOfWork.MagazineCategoryRepository.FindBy(x => x.Name == model.Name); if (exists.Any()) { return(new Result <MagazineCategory>(ResultStatus.ALREADYEXISTS, "A folyóirat már létezik! Kérem ellenőrizze az adatokat!")); } _unitOfWork.MagazineCategoryRepository.Add(model); _unitOfWork.SaveChanges(); return(new Result <MagazineCategory>(model)); } catch (Exception ex) { return(new Result <MagazineCategory>(ResultStatus.ERROR, ex.Message)); } }
// GET: MagazineCategory/Delete/5 public ActionResult Delete(int id) { BlueprintMediaServisEntity entity = new BlueprintMediaServisEntity(); MagazineCategory magazineCategoryEntity = entity.MagazineCategory.Find(id); if (magazineCategoryEntity != null) { if (magazineCategoryEntity.MagazinesContent.Count == 0) { entity.MagazineCategory.Remove(magazineCategoryEntity); entity.SaveChanges(); Session["status"] = "deleted"; return(RedirectToAction("Index")); } else { Session["status"] = "relatedEntity"; return(RedirectToAction("Index")); } } Session["status"] = "itemNotFound"; return(RedirectToAction("Index")); }
static async Task RunAsync() { string subscriberIds = null; client.BaseAddress = new Uri("http://magazinestore.azurewebsites.net/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); //get token HttpResponseMessage response = await client.GetAsync("api/token"); if (response.IsSuccessStatusCode) { var token = await response.Content.ReadAsAsync <TokenObj>(); //get categories response = await client.GetAsync("api/categories/" + token.Token); var categoryjsonStr = await response.Content.ReadAsStringAsync(); var categories = JsonConvert.DeserializeObject <CategoryObj>(categoryjsonStr); List <MagazineCategory> magList = new List <MagazineCategory>(); //loop thru each category and get list of magazines. foreach (var c in categories.data) { response = await client.GetAsync("api/magazines/" + token.Token + "/" + c); var magazineStr = await response.Content.ReadAsStringAsync(); var magazines = JsonConvert.DeserializeObject <Magazines>(magazineStr); foreach (var m in magazines.data) { MagazineCategory mag = new MagazineCategory(); mag.Id = m.Id; mag.category = m.Category; magList.Add(mag); } } //get subscribers response = await client.GetAsync("api/subscribers/" + token.Token); MagIds subMagIds = new MagIds(); var jsonStr = await response.Content.ReadAsStringAsync(); var subs = JsonConvert.DeserializeObject <Subscribers>(jsonStr); var catType = magList.GroupBy(x => x.category); bool isGoodSubscriber = false; //loop thru subscribers and check if theyre subscribe to at least one magazine each category. foreach (var s in subs.data) { subMagIds.Ids = s.MagazineIds.ToList(); foreach (var c in catType) { var singleCategory = magList.Where(o => o.category == c.Key); bool isFoundSubscriber = singleCategory.Any(row => subMagIds.Ids.Contains(row.Id)); if (isFoundSubscriber) { isGoodSubscriber = true; } else { isGoodSubscriber = false; break; } } if (isGoodSubscriber) { subscriberIds += "'" + s.Id.ToString() + "',"; } } subscriberIds = subscriberIds.TrimEnd(','); string postUrl = "api/answer/" + token.Token; var jsonString = @"{ 'subscribers': [" + subscriberIds + "]}"; var stringContent = new StringContent(JsonConvert.SerializeObject(jsonString), Encoding.UTF8, "application/json"); response = await client.PostAsync(postUrl, stringContent); var resultobj = response.Content.ReadAsStringAsync(); Console.WriteLine(resultobj.Result); } }
// GET: api/MagazineCategories public List <MagazineCategory> GetMagazineCategory() { MagazineCategory magazineCategory = new MagazineCategory(); return(magazineCategory.RetriveMagazineCategory4API()); }