Exemplo n.º 1
0
        public IActionResult AddCategory([FromBody] AdminCategoryModel model)
        {
            var profile  = GetProfile();
            var existing = this.db.Categories.Single(c => c.Title == model.Title && c.ProfileId == profile.Id);

            if (existing == null)
            {
                var newCategory = new Category
                {
                    ProfileId   = profile.Id,
                    Title       = model.Title,
                    Description = model.Title,
                    Slug        = model.Title.ToSlug(),
                    LastUpdated = SystemClock.Now()
                };

                this.db.Categories.Add(newCategory);
                this.db.Complete();

                existing = this.db.Categories.Single(c => c.Title == model.Title && c.ProfileId == profile.Id);
            }

            var callback = new { existing.Id, existing.Title };

            return(new CreatedResult("blogifier/api/categories/" + existing.Id,
                                     callback));
        }
Exemplo n.º 2
0
        public ActionResult EditCategory(AdminCategoryModel _editCategory)
        {
            string let = Request.Url.PathAndQuery;

            string[] parcalar = let.Split('=');
            _editCategory.ID = Convert.ToInt32(parcalar[1]);

            using (SinemaSitesiEntities db = new SinemaSitesiEntities())
            {
                var isThere = db.Category.Where(x => x.Name == _editCategory.Name).FirstOrDefault();
                if (isThere != null)
                {
                    ViewBag.Error = "HATA! Bu kategori ismi kayıtlarda var.Lütfen başka bir giriş yapınız.";
                    ModelState.AddModelError("", "HATA! Bu kategori ismi kayıtlarda var.Lütfen başka bir giriş yapınız.");

                    return(View(_editCategory));
                }
                else
                {
                    var data = db.Category.Find(_editCategory.ID);
                    data.Name = _editCategory.Name;

                    db.SaveChanges();
                }
            }

            return(RedirectToAction("Categories", "Admin"));
        }
Exemplo n.º 3
0
        public IActionResult CreateCategory()
        {
            var viewModel = new AdminCategoryModel
            {
                Category   = new Category("Name", new Category("ParentName")),
                Categories = _productsService.Categories
            };

            return(View("Category", viewModel));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(int id, AdminCategoryModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            await this.categoties.EditAsync(id, model.Name, model.PictureUrl);

            return(RedirectToAction(nameof(Index)));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> EditCategory(Category category)
        {
            if (ModelState.IsValid)
            {
                await _productsService._categoryRepository.SaveCategoryAsync(category);

                TempData["message"] = $"{category.Name} has been saved";
            }
            var viewModel = new AdminCategoryModel
            {
                Category   = category,
                Categories = _productsService.Categories
            };

            return(View("Categories", _productsService.Categories));
        }
Exemplo n.º 6
0
        public IActionResult EditCategory(int categoryId)
        {
            var category = _productsService._categoryRepository.Categories.FirstOrDefault(c => c.ID == categoryId);

            if (category == null)
            {
                return(NotFound());
            }

            var viewModel = new AdminCategoryModel
            {
                Category   = category,
                Categories = _productsService.Categories
            };

            return(View("Category", viewModel));
        }
Exemplo n.º 7
0
 public ActionResult AddCategory(AdminCategoryModel _category)
 {
     using (SinemaSitesiEntities db = new SinemaSitesiEntities())
     {
         var isThere = db.Category.Where(x => x.Name == _category.Name).FirstOrDefault();
         if (isThere != null)
         {
             ViewBag.Error = "HATA! Bu kategori ismi kayıtlarda var.Lütfen başka bir giriş yapınız.";
             ModelState.AddModelError("", "HATA! Bu kategori ismi kayıtlarda var.Lütfen başka bir giriş yapınız.");
             return(View());
         }
         else
         {
             Category c = new Category();
             c.Name = _category.Name;
             db.Category.Add(c);
             db.SaveChanges();
             return(RedirectToAction("Categories", "Admin"));
         }
     }
 }
        public void AddCategoryToPost([FromBody] AdminCategoryModel model)
        {
            var existing = _db.Categories.Single(c => c.Title == model.Title);

            if (existing == null)
            {
                var newCategory = new Category
                {
                    ProfileId   = GetProfile().Id,
                    Title       = model.Title,
                    Description = model.Title,
                    Slug        = model.Title.ToSlug(),
                    LastUpdated = SystemClock.Now()
                };
                _db.Categories.Add(newCategory);
                _db.Complete();

                existing = _db.Categories.Single(c => c.Title == model.Title);
            }
            _db.Categories.AddCategoryToPost(int.Parse(model.PostId), existing.Id);
            _db.Complete();
        }
 public void RemoveCategoryFromPost([FromBody] AdminCategoryModel model)
 {
     _db.Categories.RemoveCategoryFromPost(int.Parse(model.PostId), int.Parse(model.CategoryId));
     _db.Complete();
 }
Exemplo n.º 10
0
        public async Task <IActionResult> Create(AdminCategoryModel model)
        {
            await this.categoties.CreateAsync(model.Name, model.PictureUrl);

            return(RedirectToAction(nameof(Index)));
        }
 public ActionResult AddCategory(AdminCategoryModel categoryModel)
 {
     if (Session["important"] != null || Session["juststaff"] != null)
     {
         /**
          *  1. Upload fileto images dir and generate file name
          *  2. Create new category with that imgUrl file name
          */
         string defaultImgUrlPath = Server.MapPath("~/Content/Images/no_image.png");
         string newImgUrlPath     = "";
         string fileName          = "";
         int    count             = 0;
         string ext;
         string extractedName;
         var    validImageTypes = new string[]
         {
             "image/gif",
             "image/jpeg",
             "image/pjpeg",
             "image/png"
         };
         // Upload the image
         if (categoryModel.Image != null && categoryModel.Image.ContentLength > 0)
         {
             if (!validImageTypes.Contains(categoryModel.Image.ContentType))
             {
                 ViewBag.Message = "ERROR: Unknown image type";
             }
             else
             {
                 // Create new category
                 if (ModelState.IsValid)
                 {
                     try
                     {
                         fileName = Path.GetFileName(categoryModel.Image.FileName);
                         // Change file name
                         // Extract name/extension
                         extractedName = fileName.Split('.')[0];
                         ext           = fileName.Split('.')[1];
                         // Create new name+ext
                         fileName = categoryModel.Name.ToLower() + "." + ext;
                         // Save to DB
                         count = dao.InsertCategory(categoryModel.Name, categoryModel.Description, fileName);
                     }
                     catch (Exception ex)
                     {
                         ViewBag.Status = "DB ERROR!" + ex.Message;
                     }
                     if (count == 1)
                     {
                         // Upload the file
                         newImgUrlPath = Path.Combine(Server.MapPath("~/Content/Images/category/"), fileName);
                         categoryModel.Image.SaveAs(newImgUrlPath);
                         ModelState.Clear();
                         return(RedirectToAction("Index", "AdminCategory"));
                     }
                     else
                     {
                         ViewBag.Status = "ERROR! Category create fail";
                     }
                     return(View()); // Display modal to say category created
                 }
                 else
                 {
                     ViewBag.Status = "ERROR! Model Invalid";
                 }
             }
         }
         else
         {
             // No image file uploaded
             ViewBag.Status = "ERROR: No image selected";
         }
         return(View());
     }
     else
     {
         return(RedirectToAction("Index", "Home"));
     }
 }