Ejemplo n.º 1
0
 public IActionResult CreateCategory(Category category)
 {
     if (IsAdmin())
     {
         if (ModelState.IsValid)
         {
             var search = _categoryServices.GetCategory(category.CategoryId);
             if (search == null)
             {
                 if (_categoryServices.CreateCategory(category))
                 {
                     Alert("Create category successfully!", NotificationType.success);
                     return(RedirectToAction("ManageUser"));
                 }
             }
             else
             {
                 Alert("Category already exist!!", NotificationType.error);
                 return(View());
             }
         }
         return(View());
     }
     Alert("You not permit to access that page", NotificationType.warning);
     return(RedirectToAction("Index", "Home"));
 }
Ejemplo n.º 2
0
        //GET: Edit
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var category = await categoryServices.GetCategory((int)id);

            if (category == null)
            {
                return(NotFound());
            }
            return(View(category));
        }
Ejemplo n.º 3
0
        public IActionResult Update(int id)
        {
            Category         getCategory      = ICategoryServices.GetCategory(id);
            CategoryAddModel categoryAddModel = new CategoryAddModel
            {
                ID           = getCategory.CategoryID,
                CategoryName = getCategory.CategoryName
            };

            return(View(categoryAddModel));
        }
        private CategoryViewModel GetCategory(string categoryName)
        {
            var category = _categoryServices.GetCategory(categoryName);

            if (category != null)
            {
                var CategoryViewModel = _mapper.MapToCategoryViewModel(category);

                return(CategoryViewModel);
            }
            return(null);
        }
        public IActionResult Index(string category)
        {
            var pageNumber = 0;
            var obj        = _categoryServices.GetCategory(category);

            if (Request.HasFormContentType && Request.Form.ContainsKey("paging"))
            {
                pageNumber = int.Parse(Request.Form["paging"]);
            }

            var items = _projectEngine.SearchItems(null, null, categoryId: obj.Id, page: pageNumber);

            return(View(new CategoriesViewModel()
            {
                CurrentCategory = obj,
                ImageUrl = obj.ImageUrl,
                Categories = new List <Category>()
                {
                    obj
                },
                Items = items,
                PageNumber = pageNumber
            }));
        }
Ejemplo n.º 6
0
        private async Task SavePostCategory(CreatePostViewModel createPostViewModel, IPostCategoryServices postCategoryServices, ICategoryServices categoryServices)
        {
            if (createPostViewModel.SelectedCategories?.Count > 0)
            {
                foreach (string category in createPostViewModel.SelectedCategories)
                {
                    Category cat = await categoryServices.GetCategory(new Category { Name = category });

                    PostCategory postCategory = new PostCategory {
                        PostId = createPostViewModel.Post.Id, CategoryId = cat.Id
                    };
                    await postCategoryServices.SavePostCategory(postCategory);
                }
            }
        }
Ejemplo n.º 7
0
        private async Task UpdatePostCategory(CreatePostViewModel createPostViewModel, IPostCategoryServices postCategoryServices, ICategoryServices categoryServices)
        {
            //Delete existing PostCategory entries
            await DeleteExistingPostCategoryEntries(createPostViewModel.Post.Id, postCategoryServices);

            //Add new PostCategory entries if there are any entries
            if (createPostViewModel.SelectedCategories != null)
            {
                foreach (string category in createPostViewModel.SelectedCategories)
                {
                    Category cat = await categoryServices.GetCategory(new Category { Name = category });

                    PostCategory postCategory = new PostCategory {
                        PostId = createPostViewModel.Post.Id, CategoryId = cat.Id
                    };
                    await postCategoryServices.SavePostCategory(postCategory);
                }
            }
        }
Ejemplo n.º 8
0
 public Category Get(int categoryId)
 {
     return(_categoryServices.GetCategory(categoryId));
 }
Ejemplo n.º 9
0
        public TransactionResult CreateItem(string UserId, string categoryslug, string title, string description, string provinceId, string districtId, string whenTypeId, string whenDateId, string whenTimeId, IEnumerable <CategoryQuestions> questions, decimal?price, IEnumerable <IFormFile> galleryImages)
        {
            try
            {
                var today = DateTime.Now;

                var item = new Item();
                item.Id        = Guid.NewGuid();
                item.AddedDate = today;
                item.SlugUrl   = UrlConverter.ToUrlSlug(title + "-" + today.DayOfYear + today.Year);
                var category = _categoryServices.GetCategory(categoryslug);
                item.CategoryId  = category.Id;
                item.Description = description;

                int ProvinceId = 0;
                if (int.TryParse(provinceId, out ProvinceId))
                {
                    item.ProvinceId = ProvinceId;
                }

                int DistrictId = 0;
                if (int.TryParse(districtId, out DistrictId))
                {
                    item.DistrictId = DistrictId;
                }

                int WhenTypeId = 0;
                if (int.TryParse(whenTypeId, out WhenTypeId))
                {
                    item.WhenType = WhenTypeId;
                }

                if (!string.IsNullOrWhiteSpace(whenDateId) && !string.IsNullOrWhiteSpace(whenTimeId))
                {
                    var datetime = DateTime.ParseExact(whenDateId + " " + whenTimeId, "yyyyMMdd HHmm", CultureInfo.InvariantCulture);
                    item.WhenDate = datetime;
                }

                item.Price    = price;
                item.StatusID = (int)StatusTypes.Open;
                item.Title    = title;
                item.UserId   = UserId;
                item.ItemCategoryQuestionsJSON = JsonConvert.SerializeObject(questions);

                //// TODO Uncomment here
                //var upload = new FormUpload(_environment.WebRootPath);
                //var index = 0;
                //foreach (var image in galleryImages)
                //{
                //    if (image.Length != 0)
                //    {
                //        var filename = string.Format("{0}-{1}", item.Id, index);
                //        var imageResult = upload.SaveFile(image, filename, "itemgallery");

                //        if (imageResult.Type != TransactionType.Success)
                //            return imageResult;

                //        switch (index)
                //        {
                //            case 0:
                //                item.ImageUrl = imageResult.Result as string;
                //                break;

                //            case 1:
                //                item.ImageUrl2 = imageResult.Result as string;
                //                break;

                //            case 2:
                //                item.ImageUrl3 = imageResult.Result as string;
                //                break;

                //            case 3:
                //                item.ImageUrl4 = imageResult.Result as string;
                //                break;

                //            case 4:
                //                item.ImageUrl5 = imageResult.Result as string;
                //                break;
                //        }

                //        index++;
                //    }
                //}

                _dbContext.Item.Add(item);

                _dbContext.SaveChanges();
                _notificationService.AddNotification(UserId, NotificationTypes.CreateItem, itemId: item.Id.ToString());

                SendBulkSMS(item);

                return(new TransactionResult()
                {
                    Type = TransactionType.Success
                });
            }
            catch (Exception ex)
            {
                return(new TransactionResult(message: "Beklenmedik bir hata oluştu. Lütfen tekrar deneyiniz.", type: TransactionType.Error));
            }
        }
Ejemplo n.º 10
0
 public IActionResult GetCategory(string catName)
 {
     return(Ok(_categorysServices.GetCategory(catName)));
 }