コード例 #1
0
        private async Task <ResponseMessagesDto> CreateShopProductAsync(CreateShopProductDto shopProductDto)
        {
            var result = await _shopProductRepository.InsertAsync(new ShopProduct()
            {
                WholeSaleRate = shopProductDto.WholeSaleRate,
                RetailPrice   = shopProductDto.RetailPrice,
                Quantity      = shopProductDto.Quantity,
                CompanyRate   = shopProductDto.CompanyRate,
                ProductId     = shopProductDto.ProductId,
                CompanyId     = shopProductDto.CompanyId,
                Description   = shopProductDto.Description,
                TenantId      = shopProductDto.TenantId
            });

            await UnitOfWorkManager.Current.SaveChangesAsync();

            if (result.Id != 0)
            {
                return(new ResponseMessagesDto()
                {
                    Id = result.Id,
                    SuccessMessage = AppConsts.SuccessfullyInserted,
                    Success = true,
                    Error = false,
                });
            }
            return(new ResponseMessagesDto()
            {
                Id = 0,
                ErrorMessage = AppConsts.InsertFailure,
                Success = false,
                Error = true,
            });
        }
コード例 #2
0
        private async Task <ResponseMessagesDto> UpdateShopProductAsync(CreateShopProductDto shopProductDto)
        {
            var result = await _shopProductRepository.UpdateAsync(new ShopProduct()
            {
                Id            = shopProductDto.Id,
                WholeSaleRate = shopProductDto.WholeSaleRate,
                Quantity      = shopProductDto.Quantity,
                RetailPrice   = shopProductDto.RetailPrice,
                ProductId     = shopProductDto.ProductId,
                CompanyId     = shopProductDto.CompanyId,
                CompanyRate   = shopProductDto.CompanyRate,
                Description   = shopProductDto.Description
            });

            if (result != null)
            {
                return(new ResponseMessagesDto()
                {
                    Id = result.Id,
                    SuccessMessage = AppConsts.SuccessfullyUpdated,
                    Success = true,
                    Error = false,
                });
            }
            return(new ResponseMessagesDto()
            {
                Id = 0,
                ErrorMessage = AppConsts.UpdateFailure,
                Success = false,
                Error = true,
            });
        }
コード例 #3
0
        public async Task <ResponseMessagesDto> CreateOrEditAsync(CreateShopProductDto shopProductDto)
        {
            ResponseMessagesDto result;

            if (shopProductDto.Id == 0)
            {
                result = await CreateShopProductAsync(shopProductDto);
            }
            else
            {
                result = await UpdateShopProductAsync(shopProductDto);
            }
            return(result);
        }