Пример #1
0
        public async Task <IActionResult> Save(string strCategory)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            CategoryVm           categoryVm = serializer.Deserialize <CategoryVm>(strCategory);

            bool status = false;

            if (categoryVm.Id == 0)
            {
                var request = new CategoryCreateRequest();
                request.Name        = categoryVm.Name;
                request.Description = categoryVm.Description;
                request.UserId      = new Guid("69bd714f-9576-45ba-b5b7-f00649be00de");
                request.CreatedDate = DateTime.Now;

                status = await _categoryApiClient.Add(request);
            }
            else
            {
                var request = new CategoryUpdateRequest();
                request.Id          = categoryVm.Id;
                request.Name        = categoryVm.Name;
                request.Description = categoryVm.Description;
                request.UserId      = new Guid("69bd714f-9576-45ba-b5b7-f00649be00de");
                request.CreatedDate = DateTime.Now;

                status = await _categoryApiClient.Update(request);
            }

            return(Json(new { status = status }));
        }
Пример #2
0
        public async Task <ActionResult> Edit(CategoryRequest categoryRequest)
        {
            if (ModelState.IsValid)
            {
                var Token = HttpContext.Session.GetString("Token");
                if (_userClient.CheckToken(Token, User.Identity.Name) == null)
                {
                    return(Redirect("/Administration/Home/Login"));
                }
                else
                {
                    if (Token == null)
                    {
                        Token = await _userClient.CheckToken(Token, User.Identity.Name);
                    }
                }
                var result = await _categoryApi.Update(Token, categoryRequest);

                if (result > 0)
                {
                    return(Content("Success"));
                }
            }
            return(Redirect("Index"));
        }
Пример #3
0
        public async Task <IActionResult> Edit(CategoryUpdateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            var result = await _categoryApiClient.Update(request);

            if (result == 1)
            {
                TempData["result"] = "Cập danh mục thành công";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Cập nhật không thành công");
            return(View(request));
        }
Пример #4
0
        public async Task <IActionResult> Edit(CategoryUpdateRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(View(request));
            }
            if (request.LanguageId == null)
            {
                request.LanguageId = GetLanguageId();
            }
            var result = await _categoryApiCilent.Update(request);

            if (result.IsSuccessed)
            {
                TempData["Result"] = "Chỉnh sửa thành công";
                return(RedirectToAction("Index", "Category"));
            }
            ModelState.AddModelError("", result.Message);
            return(View(request));
        }