public ActionResult Delete(int memberid)
        {
            // Clinic object
            Clinic clinic = _VCRepo.Get();

            /*delte appointment first*/
            IEnumerable <Appointment> memApp = _AppRepo.GetByMemberId(memberid);

            if (memApp != null && memApp.Count() > 0)
            {
                foreach (var app in memApp)
                {   /*But first, remove appointment from time slot*/
                    // Check for time slot of each appointment
                    IEnumerable <AppointmentTimeSlot> appTimeblock = _AppTimeRepo.GetByAppointmentID(app.id);
                    if (appTimeblock != null && appTimeblock.Count() > 0)
                    {
                        foreach (var apptime in appTimeblock)
                        {
                            //Update Timeblock (2)
                            TimeSlot updateTimeBlock = _TimeSlotRepo.GetByID(apptime.timeId);
                            // 2.1 reduce number of case
                            updateTimeBlock.numberofCase -= 1;

                            // 2.2 update status
                            if (updateTimeBlock.numberofCase == 0 || updateTimeBlock.numberofCase <= clinic.maximumCase)
                            {
                                updateTimeBlock.status = "Free";
                            }

                            _TimeSlotRepo.Update(updateTimeBlock);

                            //Delete AppointmentTimeblock (1) ^
                            _AppTimeRepo.Delete(apptime);
                        }
                    }
                    // Then remove appointment (3)
                    _AppRepo.Delete(app);
                }
            }

            //Then Remove pet (4)
            IEnumerable <Pet> memPet = _PetRepo.GetByMemberID(memberid);

            if (memPet != null && memPet.Count() > 0)
            {
                foreach (var pet in memPet)
                {
                    _PetRepo.Delete(pet);
                }
            }

            Member member = _MemberRepo.GetByID(memberid);

            _MemberRepo.Delete(member);



            return(Json(new { Result = "Success" }));
        }
Exemplo n.º 2
0
        public ActionResult VASetting(string caseNumber)
        {
            Boolean isNumber = Regex.IsMatch(caseNumber, @"^\d+$");

            if (isNumber == false)
            {
                return(Json(new { Result = "Fail, maximum case can only contain numeric character" }));
            }
            Clinic clinic = _VCRepo.Get();

            clinic.maximumCase = Int32.Parse(caseNumber.ToString());
            _VCRepo.Update(clinic);

            List <AppointmentTimeSlot> appTimeblock = _AppTimeRepo.GetAll().ToList();

            if (appTimeblock != null && appTimeblock.Count > 0)
            {
                foreach (var apptime in appTimeblock)
                {
                    //Update Timeblock (2)
                    TimeSlot updateTimeBlock = _TimeSlotRepo.GetByID(apptime.timeId);
                    int      id = apptime.appointmentID;

                    // 2.2 update status
                    if (updateTimeBlock.numberofCase < clinic.maximumCase)
                    {
                        if (updateTimeBlock.numberofCase == 1 && updateTimeBlock.status == "Full")
                        {
                            // not up date --> still Full
                        }
                        else
                        {
                            updateTimeBlock.status = "Free";
                            _TimeSlotRepo.Update(updateTimeBlock);
                        }
                    }
                    else
                    {
                        if (updateTimeBlock.numberofCase == 1 && updateTimeBlock.status == "Full")
                        {
                            // not up date --> still Full
                        }
                        else
                        {
                            updateTimeBlock.status = "Busy";
                            _TimeSlotRepo.Update(updateTimeBlock);
                        }
                    }
                }
            }


            return(Json(new { Result = "Success" }));
        }