public IHttpActionResult Post(CategoryCreate category)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateCategoryService();

            if (!service.CreateCategory(category))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public bool CreateCategory(CategoryCreate model)
        {
            var entity =
                new Category()
            {
                OwnerId      = _userId,
                CategoryName = model.CategoryName,
                SectionName  = model.SectionName
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Categories.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #3
0
        public bool CreateCategory(CategoryCreate model)
        {
            var entity =
                new Category()
            {
                OwnerId     = _userId,
                Title       = model.Title,
                Description = model.Description
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Categories.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #4
0
        public bool CreateCategory(CategoryCreate model)
        {
            var entity =
                new Category()
            {
                OwnerId    = _userId,
                Name       = model.Name,
                Specifics  = model.Specifics,
                CreatedUtc = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Categories.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #5
0
        public bool CreateCategory(CategoryCreate model)
        {
            var entity =
                new Category()
            {
                CategoryId = model.CategoryId,
                Name       = model.Name,
                Popularity = model.Popularity,
                PriceRange = model.PriceRange
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Categories.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Create(CategoryCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            if ((new CategoryService()).CreateCategory(model))
            {
                TempData["SaveResult"] = "Your category was created";
                return(RedirectToAction(nameof(Index)));
            }

            ModelState.AddModelError("", "Category could not be created");
            return(View(model));
        }
Beispiel #7
0
        public bool CreateCategory(CategoryCreate model)
        {
            var entity =
                new Category()
            {
                OwnerId    = _userId,
                Title      = model.Title,
                Content    = model.Content,
                CreatedUtc = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Categorys.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
 public IActionResult Create(CategoryCreate model)
 {
     if (ModelState.IsValid)
     {
         if (categoryRepository.CreateCategory(model) > 0)
         {
             ViewBag.Categories = categoryRepository.Gets();
             return(RedirectToAction("Index", "Category"));
         }
         else
         {
             ModelState.AddModelError("", "Tên này đã tồn tại, vui lòng chọn tên khác");
         }
     }
     ViewBag.Categories = categoryRepository.Gets();
     return(View());
 }
        public ActionResult Create(CategoryCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var service = CreateCategoryService();

            if (service.CreateCategory(model))
            {
                // Use TempData rather than ViewBag. TempData removes information after it's accessed
                TempData["SaveResult"] = "Your category was created.";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "The category could not be created.");
            return(View(model));
        }
        public ActionResult Create(CategoryCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = new CategoryService();

            if (service.CreateCategory(model))
            {
                TempData["SaveResult"] = "Category Created";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Category could not be added");
            return(View(model));
        }
        public ActionResult Create(CategoryCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateCategoryService();

            if (service.CreateCategory(model))
            {
                TempData["SaveResult"] = "Your note was created.";
                return(RedirectToAction("Index"));
            }
            ;

            return(View(model));
        }
Beispiel #12
0
        public ActionResult Create(CategoryCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateCategoryService();

            if (service.CreateCategory(model))
            {
                TempData["SaveResult"] = "Your category was created";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Unable to create category");
            return(View(model));
        }
Beispiel #13
0
        public bool CreateCategory(CategoryCreate model)
        {
            if (model.CategoryName.Contains("Please"))
            {
                return(false);
            }

            Category entity = new Category
            {
                CategoryName        = model.CategoryName,
                CategoryDescription = model.CategoryDescription
            };

            using (var context = new ApplicationDbContext())
            {
                context.Categories.Add(entity);
                return(context.SaveChanges() == 1);
            }
        }
Beispiel #14
0
        public ActionResult Create(CategoryCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            if (_service.CreateCat(model))
            {
                TempData["SaveResult"] = "Your category was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Category could not be created.");

            return(View(model));
        }
        public IActionResult Add([FromBody] CategoryCreate categoryCreate)
        {
            if (categoryCreate == null)
            {
                throw new ApiException("Błąd danych");
            }

            if (!ModelState.IsValid)
            {
                throw new ApiValidationException("Walidacja");
            }

            if (!_categoryService.Save(categoryCreate))
            {
                throw new ApiException("Bład wykonano akcje zapisu kategorii");
            }

            return(new ResponseObjectResult("Pomyślnie wykonano akcje dodania kategorii"));
        }
 public async Task ValidateCreateModel(CategoryCreate model)
 {
     if (model == null)
     {
         throw new ValidationFailedException("No data provided to create category");
     }
     if (model.LanguageId <= 0)
     {
         throw new ValidationFailedException("Category must have specified language");
     }
     if (string.IsNullOrEmpty(model.Name))
     {
         throw new ValidationFailedException("Category must have a name");
     }
     if (await CategoryExists(model.LanguageId, model.Name))
     {
         throw new ValidationFailedException("Category already exists");
     }
 }
Beispiel #17
0
        public IHttpActionResult Post(CategoryCreate model)
        {
            if (model is null)
            {
                return(BadRequest(ModelState));
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var  category     = CreateCategoryService();
            bool isSuccessful = category.CreateCategory(model);

            if (isSuccessful)
            {
                return(Ok($"Category Created:{model.Name}"));
            }
            return(InternalServerError());
        }
        public Guid Create(CategoryCreate input)
        {
            // check user and permissions
            Session.EnsureAuthenticated();

            // validation
            var hasCategoryWithSameName = _categoryRepository.GetAll()
                                          .Where(x => x.ParentCategoryId == input.ParentCategoryId && x.Title == input.Title).Any();

            if (hasCategoryWithSameName)
            {
                throw new Exceptions.BadRequestException("CATEGORY_WITH_SAME_NAME_EXIST");
            }

            // build hierarchy
            var hierarchy = "";

            if (input.ParentCategoryId.HasValue)
            {
                hierarchy = input.ParentCategoryId.Value.ToString();
                var parentCategoryHierarchy = _categoryRepository.GetAll()
                                              .Where(x => x.Id == input.ParentCategoryId.Value)
                                              .Select(x => x.Hierarchy).FirstOrDefault();
                if (string.IsNullOrWhiteSpace(parentCategoryHierarchy) == false)
                {
                    hierarchy = parentCategoryHierarchy + ";" + hierarchy;
                }
            }

            var model = new Entities.Category
            {
                Id               = Guid.NewGuid(),
                CreatedAt        = DateTime.UtcNow,
                CreatedByUserId  = Session.AuthenticatedUserId.Value,
                ParentCategoryId = input.ParentCategoryId,
                Hierarchy        = hierarchy,
                Title            = input.Title
            };

            _categoryRepository.Insert(model);
            return(model.Id);
        }
Beispiel #19
0
        public ActionResult Create(CategoryCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateCategoryService();

            if (service.CreateCategory(model))
            {
                TempData["SaveResult"] = $"'{model.CategoryName}' was created";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", $"'{model.CategoryName}' could not be created.");

            return(View(model));
        }
Beispiel #20
0
        public ActionResult Create(CategoryCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = new CategoryService();

            // return service;


            if (service.CreateCategory(model))
            {
                TempData["SaveResult"] = "Your note was created.";
                return(RedirectToAction("Index"));
            }
            ;
            ModelState.AddModelError("", "Note could not be created.");
            return(View(model));
        }
        public bool CreateCategory(CategoryCreate model)
        {
            var entity =
                new Category()
            {
                CategoryName = model.CategoryName,
                CreateBy     = _userId,
                CreateAt     = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Categories.Add(entity);

                bool success = true;
                try { ctx.SaveChanges(); }
                catch { success = false; }

                return(success);
            }
        }
Beispiel #22
0
        public int CreateCategory(CategoryCreate categoryCreate)
        {
            var count = 0;

            foreach (var item in context.Categories)
            {
                if (item.CategoryName == categoryCreate.CategoryName)
                {
                    count++;
                }
            }
            if (count == 0)
            {
                var category = new Category()
                {
                    CategoryName = categoryCreate.CategoryName,
                    IsDelete     = false,
                    Status       = true
                };
                var fileName = string.Empty;
                if (categoryCreate.CategoryImage != null)
                {
                    string uploadFolder = Path.Combine(webHostEnvironment.WebRootPath, "images/Category");
                    fileName = $"{Guid.NewGuid()}_{categoryCreate.CategoryImage.FileName}";
                    var filePath = Path.Combine(uploadFolder, fileName);
                    using (var fs = new FileStream(filePath, FileMode.Create))
                    {
                        categoryCreate.CategoryImage.CopyTo(fs);
                    }
                }
                if (categoryCreate.CategoryImage == null)
                {
                    fileName = "~/images/Category/nonCat.jpg";
                }
                category.ImagePath = fileName;
                context.Categories.Add(category);
                return(context.SaveChanges());
            }
            return(0);
        }
        public bool CreateCategory(CategoryCreate model)
        {
            var entity =
                new Category()
                {
                    OwnerId = _userId,
                    Name = model.Name

                };
            using (var ctx = new ApplicationDbContext())
            {
                ctx.Categories.Add(entity);
                return ctx.SaveChanges() == 1;

            }
            //var category = new Category
            //{
            //    Name = model.Name
            //};

            //_context.Categories.Add(category);
            //return _context.SaveChanges() > 0;
        }
Beispiel #24
0
        public bool CreateCategory(CategoryCreate model)
        {
            var titleValidatorResult = CategoryTitleValidator(model.CategoryTitle);

            if (titleValidatorResult)
            {
                return(false);
            }
            else
            {
                var entity = new Category()
                {
                    UserId        = _userId,
                    CategoryTitle = model.CategoryTitle,
                    CreatedUtc    = DateTimeOffset.UtcNow
                };
                using (var ctx = new ApplicationDbContext())
                {
                    ctx.Categories.Add(entity);
                    return(ctx.SaveChanges() == 1);
                }
            }
        }
Beispiel #25
0
        public bool CreateCategory(CategoryCreate model)
        {
            var newCategory = new Category
            {
                Name        = model.Name,
                Description = model.Description,
                CreatedAt   = DateTime.Now
            };

            try
            {
                using (var ctx = new ApplicationDbContext())
                {
                    ctx.Categories.Add(newCategory);
                    return(ctx.SaveChanges() == 1);
                }
            }
            catch (Exception e)
            {
                SentrySdk.CaptureException(e);
                return(false);
            }
        }
Beispiel #26
0
        public ActionResult CreateCategory(CategoryCreate category)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri("https://localhost:44320/api/category");
                string token = DeserializeToken();
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + token);
                var postTask = client.PostAsJsonAsync <CategoryCreate>("category", category);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    return(RedirectToAction("GetCategories"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, result.Content.ReadAsStringAsync().Result);
                }
            }
            return(View(category));
        }
Beispiel #27
0
        public IActionResult Post([FromBody] CategoryCreate category)
        {
            var categoryResponse = _categoryService.Create(category);

            return(categoryResponse.ToJsonResult());
        }
Beispiel #28
0
 public bool Update(int id, CategoryCreate value)
 {
     throw new NotImplementedException();
 }
        public IActionResult CreateCategory([FromBody] CategoryCreate input)
        {
            var result = _categoryService.Create(input);

            return(Ok(result));
        }
Beispiel #30
0
 internal void OnCategoryCreate(object sender, ChannelEventArgs e)
 {
     CategoryCreate?.Invoke(sender, e.Convert <ChannelCategory>());
 }
 public async Task<CategoryCreate.response> CategoryCreate(CategoryCreate.request request, CancellationToken? token = null)
 {
     return await SendAsync<CategoryCreate.response>(request.ToXmlString(), token.GetValueOrDefault(CancellationToken.None));
 }