Пример #1
0
        public async Task <IActionResult> Post([FromBody] CategoryAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(model));
            }
            else
            {
                StringValues authorizationToken;
                Request.Headers.TryGetValue("Social_Authorization", out authorizationToken);
                var token = authorizationToken.FirstOrDefault();
                if (string.IsNullOrEmpty(token))
                {
                    return(Unauthorized());
                }
                else
                {
                    var usr = await this._socialUserManager.GetUserByTokenlAsync(token);

                    if (usr == null)
                    {
                        return(Unauthorized());
                    }

                    Category entity = Mapper.Map <Category>(model);
                    entity.SocialUserId = usr.Id;
                    this._categoryManager.Add(entity);
                    return(Ok());
                }
            }
        }
        public ActionResult Add(CategoryAddModel model)
        {
            string role = CurrentUser.Role;

            if (role != Convert.ToString((byte)UserType.Admin))
            {
                return(RedirectToAction("index", "home"));
            }
            var category = new Category();

            category.CategoryName = model.CategoryName;
            if (model.CategoryParentId != null)
            {
                category.CategoryParentId = model.CategoryParentId;
                category.CategoryType     = (byte)CategoryType.ProductGroup;
            }
            else
            {
                category.CategoryType = (byte)CategoryType.Category;
            }
            category.Status = true;
            _categoryService.AddCategory(category);
            if (model.CategoryParentId != null)
            {
                return(RedirectToAction("index", new { categoryId = model.CategoryParentId, addedCat = "true" }));
            }
            else
            {
                return(RedirectToAction("index", new { addedCat = "true" }));
            }
        }
Пример #3
0
        public void Add(CategoryAddModel model)
        {
            var category = Mapper.Map <Category>(model);

            _categoryRepository.Add(category);
            _categoryRepository.SaveChanges();
        }
        public ActionResult Add(int?categoryParentId)
        {
            string role = CurrentUser.Role;

            if (role != Convert.ToString((byte)UserType.Admin))
            {
                return(RedirectToAction("index", "home"));
            }
            CategoryAddModel category = new CategoryAddModel();

            if (categoryParentId != null)
            {
                category.CategoryType = (byte)CategoryType.ProductGroup;
                var categories = _categoryService.GetAllCategory().Where(x => x.CategoryType == (byte)CategoryType.Category);
                foreach (var item in categories)
                {
                    category.TopCategories.Add(new SelectListItem {
                        Text = item.CategoryName, Value = item.ID.ToString()
                    });
                }
            }
            else
            {
                category.CategoryType = (byte)CategoryType.Category;
            }
            return(View(category));
        }
Пример #5
0
        public async Task AddAsync(CategoryAddModel model)
        {
            var jsonData = JsonConvert.SerializeObject(model);
            var content  = new StringContent(jsonData, Encoding.UTF8, "application/json");

            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _httpContextAccessor.HttpContext.Session.GetString("token"));
            await _httpClient.PostAsync("", content);
        }
Пример #6
0
 public async Task <IActionResult> Create(CategoryAddModel model)
 {
     TempData["active"] = "category";
     if (ModelState.IsValid)
     {
         await _categoryApiService.AddAsync(model);
     }
     return(View(model));
 }
Пример #7
0
        public async Task <IActionResult> Create(CategoryAddModel model)
        {
            if (ModelState.IsValid)
            {
                await _categoryApiService.AddAsync(model);

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Пример #8
0
        public async Task <IActionResult> Create(CategoryAddModel categoryAddModel)
        {
            TempData["active"] = "category";
            if (ModelState.IsValid)
            {
                await _categoryApiService.AddAsync(categoryAddModel);

                return(RedirectToAction("Index"));
            }
            return(View(categoryAddModel));
        }
Пример #9
0
        public IActionResult Update(int id)
        {
            Category         getCategory      = ICategoryServices.GetCategory(id);
            CategoryAddModel categoryAddModel = new CategoryAddModel
            {
                ID           = getCategory.CategoryID,
                CategoryName = getCategory.CategoryName
            };

            return(View(categoryAddModel));
        }
        public async Task <IActionResult> Create(CategoryAddModel categoryAddModel)
        {
            TempData["active"] = "category";
            if (ModelState.IsValid)
            {
                await _categoryApiService.CategoryAdd(categoryAddModel);

                return(RedirectToAction("Index", "Categories", new { @area = "Admin" }));
            }
            return(View(categoryAddModel));
        }
Пример #11
0
        public async Task <IResultModel> Add(CategoryAddModel model)
        {
            var entity = _mapper.Map <CategoryEntity>(model);
            //if (await _repository.Exists(entity))
            //{
            //return ResultModel.HasExists;
            //}

            var result = await _repository.AddAsync(entity);

            return(ResultModel.Result(result));
        }
Пример #12
0
        public async Task CategoryAdd(CategoryAddModel categoryAddModel)
        {
            var           jsonData      = JsonConvert.SerializeObject(categoryAddModel);
            StringContent stringContent = new StringContent(jsonData, Encoding.UTF8, "application/json");

            _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", _httpContextAccessor.HttpContext.Session.GetString("token"));

            var responseMessage = await _httpClient.PostAsync("", stringContent);

            if (responseMessage.IsSuccessStatusCode)
            {
            }
        }
Пример #13
0
        public IActionResult Add(CategoryAddModel categoryAddModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(categoryAddModel));
            }

            else
            {
                Category category = new Category
                {
                    CategoryName = categoryAddModel.CategoryName
                };

                ICategoryServices.Add(category);
                return(RedirectToAction("Index"));
            }
        }
        public IActionResult Add(CategoryAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var success = this.categories.Add(model.Name);

            if (!success)
            {
                ModelState.AddModelError("", string.Format(categoryExistsError, model.Name));

                return(View(model));
            }

            return(RedirectToAction(nameof(Add)));
        }
Пример #15
0
        public ActionResult Add(CategoryAddModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var category = new Category
            {
                Name   = model.Name,
                UserId = CurrentUserId,
                Color  = model.Color
            };

            moneyRepository.AddCategory(category);

            return(Ok());
        }
Пример #16
0
 public static Category ConvertToEntity(this CategoryAddModel addModel)
 => new Category
 {
     Name     = addModel.Name,
     ParentId = addModel.ParentId
 };
Пример #17
0
 public Task <IResultModel> Add(CategoryAddModel model)
 {
     return(_service.Add(model));
 }
Пример #18
0
 public IActionResult Add(CategoryAddModel model)
 {
     _categoryService.Add(model);
     return(Ok());
 }
 public IActionResult Add(CategoryAddModel category)
 {
     CategoryService.Add(category);
     return(Redirect("/"));
 }