예제 #1
0
        public async Task <BillCategoryDTO> GetBillCategoryInfoAsync(Guid id)
        {
            BillCategory billCategory = await _billCategoryRepository.FirstOrDefaultAsync(id);

            if (billCategory == null)
            {
                throw new InvalidOperationException("该类型不存在");
            }
            return(_mapper.Map <BillCategoryDTO>(billCategory));
        }
예제 #2
0
        private static void BuildBillCatParameter(BillCategory billCat, string statement)
        {
            if (statement == "update")
            {
                cmd.Parameters.Add(new SqlParameter("@id", billCat.Id));
            }

            cmd.Parameters.Add(new SqlParameter("@name", billCat.Name));
            cmd.Parameters.Add(new SqlParameter("@description", billCat.Description));
            cmd.Parameters.Add(new SqlParameter("@statusid", billCat.StatusID));
        }
예제 #3
0
        public async Task DeleteBillCategoryAsync(Guid id)
        {
            BillCategory billCategory = await _billCategoryRepository.FirstOrDefaultAsync(id);

            if (billCategory == null)
            {
                throw new InvalidOperationException("该类型不存在");
            }
            _unitOfWork.RegisterDelete(billCategory);
            await _unitOfWork.CommitAsync();
        }
예제 #4
0
파일: SeedDb.cs 프로젝트: raynier809/Venta
 private void AddBill(Customer customer, Seller seller, BillCategory billCategory, BillType billType)
 {
     _context.Bills.Add(new Bill
     {
         Customer     = customer,
         Seller       = seller,
         BillCategory = billCategory,
         BillType     = billType,
         CreateDate   = DateTime.Today.ToUniversalTime(),
         EndDate      = DateTime.Today.AddDays(1).ToUniversalTime()
     });
 }
예제 #5
0
        public async Task AddBillCategoryAsync(AddBillCategoryModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Name))
            {
                throw new InvalidOperationException("类型名称不能为空");
            }
            BillCategory billCategory = await _billCategoryRepository.FirstOrDefaultAsync(m => m.UserID.Equals(model.UserID) && m.Name.Equals(model.Name));

            if (billCategory != null)
            {
                throw new InvalidOperationException("该类型名称已存在");
            }
            billCategory       = model.CopyProperties <BillCategory>();
            billCategory.Index = _billCategoryRepository.GetMaxIndex() + 1;
            _unitOfWork.RegisterAdd(billCategory);
            await _unitOfWork.CommitAsync();
        }
예제 #6
0
        private static BillCategory BindCategoryProperties(BillCategory obj, ref SqlDataReader reader)
        {
            while (reader.Read())
            {
                obj.Name        = reader.GetString(0);
                obj.Description = reader.GetString(1);

                obj.Id = (int)reader.GetSqlInt32(2);

                if (!reader.GetSqlInt32(3).IsNull)
                {
                    obj.StatusID = (int)reader.GetInt32(3);
                }
            }

            return(obj);
        }
예제 #7
0
        public static BillCategory SelectCategoryOnId(string procName, int action, int id)
        {
            BillCategory billC = new BillCategory();

            PrepareComponent();

            cmd.CommandText = procName;
            cmd.Parameters.Add(new SqlParameter("@action", action));
            cmd.Parameters.Add(new SqlParameter("@id", id));

            try
            {
                if (conn.State == ConnectionState.Open)
                {
                    conn.Close();
                }

                conn.Open();
                reader = cmd.ExecuteReader();

                while (reader.Read())
                {
                    billC.Name        = reader.GetString(0);
                    billC.Description = reader.GetString(1);
                    billC.StatusID    = (int)reader.GetInt32(2);
                    billC.Id          = (int)reader.GetSqlInt32(3);
                }
            }
            catch (Exception ex)
            {
                conn.Close();
                MessageBox.Show(ex.ToString());
            }
            finally
            {
                reader.Close();
                conn.Close();
            }

            return(billC);
        }
예제 #8
0
        public async Task EditBillCategoryAsync(EditBillCategoryModel model)
        {
            if (string.IsNullOrWhiteSpace(model.Name))
            {
                throw new InvalidOperationException("类型名称不能为空");
            }
            BillCategory billCategory = await _billCategoryRepository.FirstOrDefaultAsync(m => !m.ID.Equals(model.ID) && m.UserID.Equals(model.UserID) && m.Name.Equals(model.Name));

            if (billCategory != null)
            {
                throw new InvalidOperationException("该类型名称已存在");
            }
            billCategory = await _billCategoryRepository.FirstOrDefaultAsync(model.ID);

            if (billCategory == null)
            {
                throw new InvalidOperationException("该类型不存在");
            }
            model.CopyProperties(billCategory);
            billCategory.UpdateTime = DateTime.Now;
            _unitOfWork.RegisterEdit(billCategory);
            await _unitOfWork.CommitAsync();
        }
예제 #9
0
        /// <summary>
        /// 添加默认账单类型
        /// </summary>
        /// <param name="billCategories"></param>
        /// <param name="userID"></param>
        /// <returns></returns>
        private async Task AddDefaultBillCategory(ICollection <BillCategory> billCategories, Guid userID)
        {
            var defaultNames = new[]
            {
                "日常消费",
                "娱乐",
                "其他"
            };

            for (int i = 0; i < defaultNames.Length; i++)
            {
                var billCategory = new BillCategory
                {
                    ID     = Guid.NewGuid(),
                    Name   = defaultNames[i],
                    UserID = userID,
                    Index  = i
                };
                _unitOfWork.RegisterAdd(billCategory);
                billCategories.Add(billCategory);
            }
            await _unitOfWork.CommitAsync();
        }