public IActionResult GetBlocks(string id) { if (id == null) { return(Ok(_blockService.GetBlocks())); } return(Ok(_blockService.GetBlocks(id))); }
public ActionResult AllBlock([FromQuery] DateTime date, string specialityId, string doctorId) { try { doctorId = doctorId == null ? "" : doctorId; specialityId = specialityId == null ? "" : specialityId; var blocks = _blockService.GetBlocks(b => b.Date == date && b.IsAvailable && b.DoctorId.Contains(doctorId) && b.Scheduling.SpecialityId.Contains(specialityId)); var groupBySpeciality = blocks.GroupBy(s => s.Scheduling.SpecialityName); List <ManageBlockVM> result = new List <ManageBlockVM>(); //Lấy block theo speciality foreach (var speciality in groupBySpeciality) { var itemSpeciality = new ManageBlockVM() { SpecialityName = speciality.Key, SpecialityId = speciality.ToList()[0].Scheduling.SpecialityId }; var groupByDoctor = speciality.GroupBy(_ => _.DoctorId); //Lấy block theo doctor foreach (var doctor in groupByDoctor) { var itemDoctor = new DoctorBookingVM() { FullName = _doctorService.GetDoctorBasic(doctor.Key).FullName, Id = doctor.Key }; itemDoctor.Blocks.AddRange(doctor.OrderByDescending(s => s.Date).Select(s => s.Adapt <BlockVM>())); //Chay tất cả các block của 1 bác sĩ foreach (var item in itemDoctor.Blocks) { //lấy ra các Ticket của block foreach (var ticket in _ticketService.GetTickets(_ => _.BlockId == item.Id)) { if (ticket.CustomerId != null) { var cus = _customerService.GetCustomer(Guid.Parse(ticket.CustomerId)).Adapt <TicketBookingVM>(); cus.Note = ticket.Note; cus.TicketId = ticket.Id; item.Customers.Add(cus); } else { item.Customers.Add(null); } } } itemDoctor.Blocks = itemDoctor.Blocks.OrderBy(_ => _.StartTime).ToList(); itemSpeciality.Doctors.Add(itemDoctor); } result.Add(itemSpeciality); } return(Ok(result)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <ActionResult> ActiveTicketAsync([FromBody] List <string> Schedulings) { try { foreach (var schedulingId in Schedulings) { var scheduling = _schedulingService.GetScheduling(Guid.Parse(schedulingId)); if (!scheduling.IsAvailable) { scheduling.IsAvailable = true; var blocks = _blockService.GetBlocks(_ => _.SchedulingId == Guid.Parse(schedulingId)); foreach (var block in blocks) { block.IsAvailable = true; //create tickets for each block (số lượng ticket dựa vào số lượng totalticket trong block) int count = 0;//index của ticket for (int j = 0; j < block.TotalTicket; j++) { Ticket ticket = new Ticket(); ticket.BlockId = block.Id; ticket.DateCreated = DateTime.Now; ticket.Index = (++count).ToString(); _ticketService.CreateTicket(ticket, (await _userManager.GetUserAsync(User)).UserName); } } } } _schedulingService.Save(); //lấy những bác sĩ được xếp lịch để gửi mail List <string> doctorIds = new List <string>(); foreach (var schedulingId in Schedulings) { var doctorId = _schedulingService.GetScheduling(Guid.Parse(schedulingId)).DoctorId; doctorIds.Add(doctorId); } foreach (var data in doctorIds.GroupBy(_ => _)) { var doctor = _doctorService.GetDoctorBasic(data.Key); EmailModel email = new EmailModel(); email.ToMail = doctor.Email; email.Subject = "This is subject"; email.Message = "Vô coi lịch trực của mày kìa"; _emailService.SendEmail(email); } return(Ok()); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <PagedResultModel <IEnumerable <BlockModel> > > GetBlocks(PagingModel paging) { var key = $"Blocks_{paging.PageNumber}_{paging.PageSize}"; if (!_memoryCache.TryGetValue(key, out PagedResult <IEnumerable <Block> > blocks)) { blocks = await _blockService.GetBlocks(_mapper.Map <Paging>(paging)); CacheItemKeys.Keys.Add(key); _memoryCache.Set(key, blocks); } return(_mapper.Map <PagedResultModel <IEnumerable <BlockModel> > >(blocks)); }
public IList <Block> Blocks() { IList <Block> blocks = _blockService.GetBlocks(); return(blocks); }
public ActionResult Blocks() { var list = _blockService.GetBlocks(); return(PartialView(list)); }