示例#1
0
        public async Task <IActionResult> Edit(long id)
        {
            try
            {
                adminTempStatu = Convert.ToBoolean(HttpContext.Session.GetString("AdminStatu"));

                if (adminTempStatu)
                {
                    EntryRestfulService service = new EntryRestfulService();
                    Entry data = await service.GetEntryAsync(id);

                    CategoryRestfulService categoryService = new CategoryRestfulService();
                    List <Category>        CategoryList    = await categoryService.ListCategoryAsync();

                    ViewBag.Categories = CategoryList;

                    return(View(data));
                }
                else
                {
                    return(Redirect("/Admin/Index"));
                }
            }
            catch (Exception)
            {
                return(Redirect("/Admin/Index"));
            }
        }
示例#2
0
        public async Task <IActionResult> Save(Entry data)
        {
            try
            {
                adminTempStatu = Convert.ToBoolean(HttpContext.Session.GetString("AdminStatu"));

                if (adminTempStatu)
                {
                    if (ModelState.IsValid)
                    {
                        try
                        {
                            EntryRestfulService    serviceEntry    = new EntryRestfulService();
                            CategoryRestfulService serviceCategory = new CategoryRestfulService();

                            Category category = await serviceCategory.GetCategoryAsync(data.CategoryId);

                            var clearHtmlTags = Regex.Replace(data.Content, "<.*?>", String.Empty);

                            data.Summary      = clearHtmlTags.Length > 200 ? clearHtmlTags.Substring(0, 200) + " ..." : clearHtmlTags;
                            data.CategoryName = category.Title;
                            data.CreateDate   = DateTime.Now;

                            await serviceEntry.PostEntry(data);

                            TempData["Result"] = "Entry başarıyla kaydedildi.";

                            return(Redirect("/Admin/Entry"));
                        }
                        catch (Exception)
                        {
                            TempData["Result"] = "Entry kaydedilirken hata ile karşılaşıldı.";
                            return(Redirect("/Admin/Entry"));
                        }
                    }
                    else
                    {
                        TempData["Result"] = "Gönderilen veri modeli istenilen şekilde değil.";
                        return(Redirect("/Admin/Entry"));
                    }
                }
                else
                {
                    return(Redirect("/Admin/Index"));
                }
            }
            catch (Exception)
            {
                return(Redirect("/Admin/Index"));
            }
        }
示例#3
0
        public async Task <IActionResult> Save(Category data)
        {
            try
            {
                adminTempStatu = Convert.ToBoolean(HttpContext.Session.GetString("AdminStatu"));

                if (adminTempStatu)
                {
                    if (ModelState.IsValid)
                    {
                        try
                        {
                            CategoryRestfulService serviceCategory = new CategoryRestfulService();
                            data.CreateDate = DateTime.Now;

                            await serviceCategory.PostCategory(data);

                            TempData["Result"] = "Entry başarıyla kaydedildi.";

                            return(Redirect("/Admin/Category"));
                        }
                        catch (Exception)
                        {
                            TempData["Result"] = "Entry kaydedilirken hata ile karşılaşıldı.";
                            return(Redirect("/Admin/Category"));
                        }
                    }
                    else
                    {
                        TempData["Result"] = "Gönderilen veri modeli istenilen şekilde değil.";
                        return(Redirect("/Admin/Category"));
                    }
                }
                else
                {
                    return(Redirect("/Admin/Index"));
                }
            }
            catch (Exception)
            {
                return(Redirect("/Admin/Index"));
            }
        }
示例#4
0
        public async Task <IActionResult> Delete(long id)
        {
            try
            {
                adminTempStatu = Convert.ToBoolean(HttpContext.Session.GetString("AdminStatu"));

                if (adminTempStatu)
                {
                    if (ModelState.IsValid)
                    {
                        try
                        {
                            CategoryRestfulService serviceCategory = new CategoryRestfulService();

                            await serviceCategory.DeleteCategory(id);

                            TempData["Result"] = "Kategori başarıyla silindi.";

                            return(Redirect("/Admin/Category"));
                        }
                        catch (Exception)
                        {
                            TempData["Result"] = "Kategori silinirken hatayla karşılaşıldı.";
                            return(Redirect("/Admin/Category"));
                        }
                    }
                    else
                    {
                        TempData["Result"] = "Silinecek kaydın Id bilgisi gönderilmelidir.";
                        return(Redirect("/Admin/Category"));
                    }
                }
                else
                {
                    return(Redirect("/Admin/Index"));
                }
            }
            catch (Exception)
            {
                return(Redirect("/Admin/Index"));
            }
        }
示例#5
0
        public async Task <IActionResult> Category()
        {
            var adminTempStatu = HttpContext.Session.GetString("AdminStatu");

            if (adminTempStatu != null)
            {
                if (Convert.ToBoolean(adminTempStatu))
                {
                    CategoryRestfulService service = new CategoryRestfulService();
                    List <Category>        data    = await service.ListCategoryAsync();

                    return(View(data));
                }
                else
                {
                    return(Redirect("Index"));
                }
            }
            else
            {
                return(Redirect("Index"));
            }
        }