Exemplo n.º 1
0
        //public IResult GetStudent(GetStudentRequest request)
        //{
        //    var student = _dataSource.Students.GetStudent(request);
        //    return new Result<Student>(true, student, "Operation completed successfully.");
        //}

        public IResult BuyVoucher(BuyVoucherRequest request)
        {
            var voucher = _dataSource.Vouchers.GetById(request.VoucherId);

            if (voucher == null)
            {
                return(new Result(false, "Voucher does not exist."));
            }
            if (voucher.Used is true)
            {
                return(new Result(false, "Voucher has been used."));
            }
            var student = _dataSource.Students.GetByIndexNumber(request.IndexNumber);

            if (student is null)
            {
                return(new Result(false, "Invalid index number."));
            }
            var transaction = new StudentTransaction {
                Amount = voucher.Amount, IndexNumber = student.IndexNumber
            };
            var result = _dataSource.Students.BuyVoucher(transaction);

            _dataSource.Vouchers.UpdateVoucher(request.VoucherId);
            //_dataSource.Transactions.Add(transaction);
            return(new Result <float>(true, result.Balance, "Operation completed successfully."));
        }
Exemplo n.º 2
0
        public IResult MakePayment(MakePaymentRequest request)
        {
            var student = _dataSource.Students.GetByIndexNumber(request.IndexNumber);

            if (student is null)
            {
                return(new Result(false, "Invalid index number."));
            }
            var transaction = new StudentTransaction
            {
                Amount      = -Math.Abs(request.Amount),
                IndexNumber = request.IndexNumber
            };

            var result = _dataSource.Students.MakePayment(transaction);

            if (result.Success)
            {
                return(new Result <float>(true, result.Balance, "Operation completed successfully."));
            }
            return(new Result <float>(false, result.Balance, "Operation failed."));
        }
Exemplo n.º 3
0
        public void Edit(StudentTransaction entity)
        {
            StudentTransactionDAL dalObject = new StudentTransactionDAL();

            dalObject.Edit(entity);
        }
Exemplo n.º 4
0
        public void Add(StudentTransaction entity, int SchoolId)
        {
            StudentTransactionDAL dalObject = new StudentTransactionDAL();

            dalObject.Add(entity, SchoolId);
        }
Exemplo n.º 5
0
        public void AddUserToGroup(HomeServerContext context, int studentId, int groupId, DateTime date)
        {
            Student student = context.Students.Find(studentId);
            Group group = context.Groups.Find(groupId);

            if (student == null)
                return;

            if (group == null)
                return;

            if(group.Students.Contains(student))
                return;

            student.GroupId = group.Id;

            //get active packs for this group
            var temp = context.Packs.Where(p => p.Course.CourseStateId == 2).ToList();

            List<Pack> packs = new List<Pack>();

            foreach(var t in temp)
            {
                foreach(var g in t.Groups)
                {
                    if (g.Id == groupId)
                    {
                        packs.Add(t);
                    }
                }
            }

            //add visits and studentProcs for each packs
            foreach(var pack in packs)
            {
                foreach(var lesson in pack.Lessons)
                {
                    if(lesson.Date < date)
                        continue;

                    lesson.Visits.Add(new Visit()
                    {
                        StudentId = student.Id,
                        Values = new List<VisitValue>()
                        {
                            new VisitValue()
                            {
                                Value = VisitValue.DEFAULT_VALUE,
                                Version = 1
                            }
                        }
                    });
                }

                foreach(var workProc in pack.WorkProcs)
                {
                    var work = context.Works.Find(workProc.WorkId);
                    work.WorkStages = context.WorkStages.Where(ws => ws.WorkId == workProc.WorkId).ToList();

                    StudentWorkProc studentProc = new StudentWorkProc()
                    {
                        StudentId = student.Id,
                        Values = new List<StudentWorkProcValue>() { new StudentWorkProcValue() { Version = 1 } },
                        StudentStageProcs = new List<StudentStageProc>()
                    };

                    foreach (var workStage in work.WorkStages)
                    {
                        studentProc.StudentStageProcs.Add(new StudentStageProc()
                        {
                            WorkStageId = workStage.Id,
                            Values = new List<StudentStageProcValue>() { new StudentStageProcValue() { Version = 1 } }
                        });
                    }

                    workProc.StudentWorkProcs.Add(studentProc);
                }
            }

            StudentTransaction studentTransaction = new StudentTransaction()
            {
                Student = student,
                Group = group,
                Date = date
            };

            context.StudentTransaction.Add(studentTransaction);

            context.SaveChanges();
        }
Exemplo n.º 6
0
        public void RemoveUserFromGroup(HomeServerContext context, int studentId)
        {
            Student student = context.Students.Find(studentId);

            if (student == null)
            {
                return;
            }
            else
            {
                student.GroupId = null;

                StudentTransaction studentTransaction = new StudentTransaction()
                {
                    Student = student,
                    GroupId = null,
                    Date = DateTime.Now
                };

                context.StudentTransaction.Add(studentTransaction);

                context.SaveChanges();
            }
        }
 public bool Add(StudentTransaction transaction)
 {
     DataWriter.Add(transaction, "Transactions");
     return(true);
 }