示例#1
0
        /// <summary>
        /// Creates a new user bill.
        /// </summary>
        /// <param name="userId">The user id</param>
        /// <param name="bill">The bill object</param>
        /// <param name="recModel">The recurrence model</param>
        /// <param name="recSchedule">The recurrence schedule</param>
        /// <returns></returns>
        public bool CreateNewUserBill(int userId, Bill bill, IRecurrenceModel recModel, RecurrenceSchedule recSchedule)
        {
            try
            {
                var newBill = _billRepository.CreateNewBill(bill);

                var newRecSchedule = _userBillRecurrenceScheduleRepository.CreateNewRecurrenceSchedule(recSchedule.RecurrenceTypeId, recSchedule.Schedule);

                _userBillRepository.CreateNewUserBill(userId, newBill, recModel, newRecSchedule);
            }
            catch (Exception e)
            {
                _logRepository.WriteLog(LogLevel.Error, "UserBillService.CreateNewUserBill", e.Message, e);
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Create a new user bill
        /// </summary>
        /// <param name="userId">The user id</param>
        /// <param name="bill">The bill model</param>
        /// <param name="model">The recurrence model</param>
        /// <param name="recurrenceSchedule">The recurrence schedule</param>
        public void CreateNewUserBill(int userId, Bill bill, IRecurrenceModel model, RecurrenceSchedule recurrenceSchedule)
        {
            using var ctx = new MyBillsContext();
            var billDetail = new UserBillDetail
            {
                UserId               = userId,
                BillId               = bill.Id,
                Month                = DateTime.Today.Month,
                Year                 = DateTime.Today.Year,
                RecurrenceTypeName   = recurrenceSchedule.RecurrenceType.Name,
                RecurrenceTypeId     = recurrenceSchedule.RecurrenceTypeId,
                Schedule             = recurrenceSchedule.Schedule,
                RecurrenceScheduleId = recurrenceSchedule.Id
            };

            CreateUserBills(ctx, model, billDetail);

            ctx.SaveChanges();
        }
        /// <summary>
        /// Get the recurrence schedule
        /// </summary>
        /// <param name="recTypeId">The recurrence type id</param>
        /// <param name="recModel">The recurrence model</param>
        /// <returns></returns>
        public RecurrenceSchedule GetRecSchedule(int recTypeId, IRecurrenceModel recModel)
        {
            var recModelFormat = recModel.Format;

            RecurrenceSchedule recurrenceSchedule;

            using (var ctx = new MyBillsContext())
            {
                recurrenceSchedule = (from ubrs in ctx.UserBillRecurrenceSchedule
                                      where ubrs.RecurrenceTypeId == recTypeId && ubrs.Schedule == recModelFormat
                                      select ubrs).FirstOrDefault();
            }

            return(recurrenceSchedule ?? (new RecurrenceSchedule
            {
                RecurrenceType = new RecurrenceType {
                    Id = 0, Name = recModel.Name, Type = recModel.Name
                },
                RecurrenceTypeId = recTypeId,
                Schedule = recModel.Format,
            }));
        }
示例#4
0
 /// <summary>
 /// Gets the recurrence schedule.
 /// </summary>
 /// <param name="recurrenceTypeId">The recurrence type id</param>
 /// <param name="recModel">The recurrence model</param>
 /// <returns></returns>
 public RecurrenceSchedule GetRecSchedule(int recurrenceTypeId, IRecurrenceModel recModel)
 {
     return(_userBillRecurrenceScheduleRepository.GetRecSchedule(recurrenceTypeId, recModel));
 }