private async Task UpdateCategoryAsync(CategoryEditDto input)
        {
            var tenantId = AbpSession.TenantId.Value;
            var category = await _categoryRepository.FirstOrDefaultAsync(c => c.Id == input.Id && c.TenantId == tenantId);

            input.MapTo(category);
        }
        /// <summary>
        /// 编辑分类
        /// </summary>
        protected virtual async Task UpdateCategoryAsync(CategoryEditDto input)
        {
            var entity = await _categoryRepository.GetAsync(input.Id.Value);

            input.MapTo(entity);
            await _categoryRepository.UpdateAsync(entity);
        }
        private async Task CreateCategoryAsync(CategoryEditDto input)
        {
            var category = input.MapTo <Category>();

            category.TenantId = AbpSession.TenantId.Value;
            await _categoryRepository.InsertAsync(category);
        }
Exemple #4
0
        /// <summary>
        /// 新增分类
        /// </summary>
        protected virtual async Task <CategoryEditDto> CreateCategoryAsync(CategoryEditDto input)
        {
            var entity = input.MapTo <Category>();

            entity = await _categoryRepository.InsertAsync(entity);

            return(entity.MapTo <CategoryEditDto>());
        }
        public async Task <IActionResult> EditCategory(CategoryEditDto model)
        {
            if (ModelState.IsValid)
            {
                await _categoryService.UpdateAsync(_mapper.Map <Category>(model));

                return(RedirectToAction("Index", "Category", new { area = "Member" }));
            }
            return(View(model));
        }
        public virtual async Task UpdateCategoryAsync(CategoryEditDto input)
        {
            //TODO:更新前的逻辑判断,是否允许更新

            var entity = await _categoryRepository.GetAsync(input.Id.Value);

            input.MapTo(entity);

            await _categoryRepository.UpdateAsync(entity);
        }
        public virtual async Task <CategoryEditDto> CreateCategoryAsync(CategoryEditDto input)
        {
            //TODO:新增前的逻辑判断,是否允许新增

            var entity = input.MapTo <Category>();

            entity = await _categoryRepository.InsertAsync(entity);

            return(entity.MapTo <CategoryEditDto>());
        }
 public async Task CreateOrUpdateCategory(CategoryEditDto input)
 {
     if (input.Id.HasValue)
     {
         await UpdateCategoryAsync(input);
     }
     else
     {
         await CreateCategoryAsync(input);
     }
 }
        public async void Update_ShouldReturnBadRequest_WhenCategoryIdIsDifferentThenParameterId()
        {
            var categoryEditDto = new CategoryEditDto()
            {
                Id = 1, Name = "Test"
            };

            var result = await _categoriesController.Update(2, categoryEditDto);

            Assert.IsType <BadRequestResult>(result);
        }
        protected virtual async Task Update(CategoryEditDto input)
        {
            //TODO:更新前的逻辑判断,是否允许更新

            var entity = await _entityRepository.GetAsync(input.Id.Value);

            input.MapTo(entity);

            // ObjectMapper.Map(input, entity);
            await _entityRepository.UpdateAsync(entity);
        }
        public async Task <IActionResult> Edit(CategoryEditDto category)
        {
            if (ModelState.IsValid)
            {
                await _categoryService.UpdateAsync(category.Adapt <Category>());

                return(RedirectToAction("Index", "Category", new { area = "Admin" }));
            }

            return(View(category));
        }
        protected virtual async Task <CategoryEditDto> Create(CategoryEditDto input)
        {
            //TODO:新增前的逻辑判断,是否允许新增

            // var entity = ObjectMapper.Map <Category>(input);
            var entity = input.MapTo <Category>();


            entity = await _entityRepository.InsertAsync(entity);

            return(entity.MapTo <CategoryEditDto>());
        }
        public async void Update_ShouldReturnBadRequest_WhenModelStateIsInvalid()
        {
            var categoryEditDto = new CategoryEditDto()
            {
                Id = 1
            };

            _categoriesController.ModelState.AddModelError("Name", "The field name is required");

            var result = await _categoriesController.Update(1, categoryEditDto);

            Assert.IsType <BadRequestResult>(result);
        }
Exemple #14
0
        public async Task <JsonResult> UdateCol(CategoryEditDto categoryEditDto)
        {
            //更新实体
            try
            {
                await _iCategoryAppService.UpdateCategoryAsync(categoryEditDto);

                return(Json(new { }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception)
            {
                return(Json("false"));
            }
        }
        public async void Update_ShouldReturnOk_WhenCategoryIsUpdatedCorrectly()
        {
            var category        = CreateCategory();
            var categoryEditDto = new CategoryEditDto()
            {
                Id = category.Id, Name = "Test"
            };

            _mapperMock.Setup(m => m.Map <Category>(It.IsAny <CategoryEditDto>())).Returns(category);
            _categoryServiceMock.Setup(c => c.GetById(category.Id)).ReturnsAsync(category);
            _categoryServiceMock.Setup(c => c.Update(category)).ReturnsAsync(category);

            var result = await _categoriesController.Update(categoryEditDto.Id, categoryEditDto);

            Assert.IsType <OkObjectResult>(result);
        }
Exemple #16
0
        public UpdateCategory(CategoryEditDto categoryEditDto, CategoryBase categoryBase)
        {
            InitializeComponent();
            this._categoryBase = categoryBase;
            categoryController = new CategoryController(categoryService);
            categoryName.Text  = categoryEditDto.categoryName;
            categoryLimit.Text = categoryEditDto.categoryLimit.ToString();
            categoryId         = categoryEditDto.categoryId;

            comboBox1.Items.Add(new KeyValuePair <string, int>("Income", 0));
            comboBox1.Items.Add(new KeyValuePair <string, int>("Expense", 1));

            comboBox1.DisplayMember = "key";
            comboBox1.ValueMember   = "value";
            comboBox1.Text          = categoryEditDto.categoryType;
        }
        public async void Update_ShouldCallUpdateFromService_OnlyOnce()
        {
            var category        = CreateCategory();
            var categoryEditDto = new CategoryEditDto()
            {
                Id = category.Id, Name = "Test"
            };

            _mapperMock.Setup(m => m.Map <Category>(It.IsAny <CategoryEditDto>())).Returns(category);
            _categoryServiceMock.Setup(c => c.GetById(category.Id)).ReturnsAsync(category);
            _categoryServiceMock.Setup(c => c.Update(category)).ReturnsAsync(category);

            await _categoriesController.Update(categoryEditDto.Id, categoryEditDto);

            _categoryServiceMock.Verify(mock => mock.Update(category), Times.Once);
        }
Exemple #18
0
        public async Task <IActionResult> Update(int id, CategoryEditDto categoryDto)
        {
            if (id != categoryDto.Id)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await _categoryService.Update(_mapper.Map <Category>(categoryDto));

            return(Ok(categoryDto));
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            CategoryEditDto categoryEditDto = new CategoryEditDto();
            string          categoryType    = this.dataGridView1.CurrentRow.Cells["categoryType"].Value.ToString();
            string          categoryName    = this.dataGridView1.CurrentRow.Cells["categoryName"].Value.ToString();
            int             categoryId      = int.Parse(this.dataGridView1.CurrentRow.Cells["categoryId"].Value.ToString());
            double          categoryLimit   = double.Parse(this.dataGridView1.CurrentRow.Cells["categoryLimit"].Value.ToString());

            categoryEditDto.categoryId    = categoryId;
            categoryEditDto.categoryName  = categoryName;
            categoryEditDto.categoryType  = categoryType;
            categoryEditDto.categoryLimit = categoryLimit;
            UpdateCategory updateCategory = new UpdateCategory(categoryEditDto, this);

            updateCategory.Show();
        }
Exemple #20
0
        public Category Make(CategoryEditDto model)
        {
            var result = _repo.Find(model.Id);

            result.Slug        = model.Slug.MakeSlug();
            result.Title       = model.Title;
            result.Description = model.Description;
            result.ParentId    = model.ParentId;
            result.LangId      = model.LangId;
            result.Status      = model.Enabled
                ? EntityStatus.Enabled
                : EntityStatus.Disabled;
            result.ModifyDate     = _dateService.UtcNow();
            result.ModifierUserId = _userContext.UserId;

            return(result);
        }
Exemple #21
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(categoryName.Text))
            {
                MessageBox.Show("Please Enter Category Name");
                return;
            }
            if (string.IsNullOrEmpty(categoryLimit.Text))
            {
                MessageBox.Show("Please Enter Category Amount");
                return;
            }
            if (!categoryLimit.Text.All(char.IsDigit))
            {
                MessageBox.Show("Please Enter Numeric Amount");
                return;
            }
            if (this.comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("Please Select a Category Type");
                return;
            }
            CategoryEditDto categoryEditDto = new CategoryEditDto();

            categoryEditDto.categoryId   = this.categoryId;
            categoryEditDto.categoryName = categoryName.Text;
            KeyValuePair <string, int> keyValue = (KeyValuePair <string, int>)comboBox1.SelectedItem;

            categoryEditDto.categoryType  = keyValue.Key;
            categoryEditDto.categoryLimit = double.Parse(categoryLimit.Text);
            object response = categoryController.updateCategory(categoryEditDto);

            if (response is Exception)
            {
                MessageBox.Show("Error Updating Transaction");
            }
            else
            {
                MessageBox.Show("Transaction Updated Successfully");
            }
            this.refreshTransactionList();
            this.Hide();
        }
        public JsonResult UpdateCategory(CategoryEditDto categoryEdit)
        {
            bool   status = false;
            string msg    = "";

            CheckModelState();

            try
            {
                _categoryAppService.UpdateCategoryAsync(categoryEdit);
                status = true;
            }
            catch (Exception e)
            {
                msg    = "-1";
                status = false;
            }
            return(Json(new { success = status }));
        }
Exemple #23
0
 public async Task CreateOrEditAsync(CategoryEditDto dto)
 {
     if (_AbpSession.TenantId != null)
     {
         dto.TenantId = (int)_AbpSession.TenantId;
     }
     else
     {
         dto.TenantId = 0;
     }
     throw new UserFriendlyException("ss");
     if (dto.Id > 0)
     {
         await _Repository.UpdateAsync(dto.MapTo <model.Category>());
     }
     else
     {
         await _Repository.InsertAsync(dto.MapTo <model.Category>());
     }
 }
Exemple #24
0
        /// <summary>
        /// 通过Id获取分类信息进行编辑或修改
        /// </summary>
        public async Task <GetCategoryForEditOutput> GetCategoryForEditAsync(NullableIdDto <int> input)
        {
            var output = new GetCategoryForEditOutput();

            CategoryEditDto categoryEditDto;

            if (input.Id.HasValue)
            {
                var entity = await _categoryRepository.GetAsync(input.Id.Value);

                categoryEditDto = entity.MapTo <CategoryEditDto>();
            }
            else
            {
                categoryEditDto = new CategoryEditDto();
            }

            output.Category = categoryEditDto;
            return(output);
        }
        public IActionResult EditCategory(int id)
        {
            if (id == 0)
            {
                TempData["Error"] = "Kategori belirlenemedi.";
                return(RedirectToAction("Index"));
            }

            var category = new CategoryEditDto
            {
                Category     = CategoryService.Instance.GetCategory(id),
                CategoryList = CategoryService.Instance.GetCategoryList()
            };

            if (category.Category == null)
            {
                TempData["Error"] = "Kategori bulunamadı.";
                return(RedirectToAction("Index"));
            }
            return(View(category));
        }
        public async Task <GetCategoryForEditOutput> GetForEdit(NullableIdDto <long> input)
        {
            var             output = new GetCategoryForEditOutput();
            CategoryEditDto editDto;

            if (input.Id.HasValue)
            {
                var entity = await _entityRepository.GetAsync(input.Id.Value);

                editDto = entity.MapTo <CategoryEditDto>();

                //categoryEditDto = ObjectMapper.Map<List<categoryEditDto>>(entity);
            }
            else
            {
                editDto = new CategoryEditDto();
            }

            output.Category = editDto;
            return(output);
        }
Exemple #27
0
        public async Task <IActionResult> Add(long?id)
        {
            List <DropDownDto> dtoList = _AppService.GetCategoryDropDownList(AbpSession.TenantId, 0);

            ViewData.Add("cat", new Microsoft.AspNetCore.Mvc.Rendering.SelectList(dtoList, "Id", "Title"));

            List <BrandSelectDto> d = _brandAppService.GetMultiSelect();

            ViewData.Add("brand", d);
            if (id == null)
            {
                var s = new CategoryEditDto();
                s.Id       = 0;
                s.TenantId = _AbpSession.TenantId;
                return(PartialView("_Add", s));
            }

            var dtos = await _AppService.GetByIdAsync((long)id);

            return(PartialView("_Add", dtos));
        }
 public async Task CreateOrEditAsync(CategoryEditDto dto)
 {
     try
     {
         if (dto.Id > 0)
         {
             await _Repository.UpdateAsync(dto.MapTo <GoodsCategory>());
         }
         else
         {
             if (_AbpSession.TenantId != null)
             {
                 dto.TenantId = (int)_AbpSession.TenantId;
             }
             await _Repository.InsertAsync(dto.MapTo <GoodsCategory>());
         }
     }
     catch (Exception e)
     {
         throw new UserFriendlyException(e.Message);
     }
 }
        public object updateCategory(CategoryEditDto categoryEditDto)
        {
            string       sql            = "update category set categoryName=@categoryName, categoryType=@categoryType, categoryLimit=@categoryLimit  where categoryId=@categoryId";
            MySqlCommand updateCategory = new MySqlCommand(sql);

            updateCategory.Parameters.AddWithValue("@categoryName", categoryEditDto.categoryName);
            updateCategory.Parameters.AddWithValue("@categoryType", categoryEditDto.categoryType);
            updateCategory.Parameters.AddWithValue("@categoryLimit", categoryEditDto.categoryLimit);
            updateCategory.Parameters.AddWithValue("@categoryId", categoryEditDto.categoryId);


            int row = dBAccess.executeQuery(updateCategory);

            if (row < 0)
            {
                throw new Exception();
            }
            else
            {
                SuccessResponse successResponse = new SuccessResponse();
                return(successResponse);
            }
        }
Exemple #30
0
        public async Task <ActionResult> CreateOrEditModal(int?Id)
        {
            var cateGoryAllList = _iCategoryAppService.GetCategorysList(new GetCategoryInput {
                FilterText = ""
            });

            ViewBag.cateGoryList = cateGoryAllList;


            if (Id.HasValue)
            {
                var cateGoryList = await _iCategoryAppService.GetCategoryForEditAsync(new NullableIdDto <int> {
                    Id = Id
                });

                return(PartialView("_CreateOrEditModal", cateGoryList.Category));
            }
            else
            {
                CategoryEditDto categoryEdit = new CategoryEditDto();
                return(PartialView("_CreateOrEditModal", categoryEdit));
            }
        }