예제 #1
0
        public async Task <IActionResult> Search(string name)
        {
            var pharmacySystems = await _pharmacySystemService.GetAll();

            List <SearchResultDto> result = new List <SearchResultDto>();

            foreach (PharmacySystem pharmacySystem in pharmacySystems)
            {
                if (_adapterContext.SetPharmacySystemAdapter(pharmacySystem) == null)
                {
                    continue;
                }

                List <DrugDto> search = new List <DrugDto>();
                search.AddRange(_adapterContext.PharmacySystemAdapter.DrugAvailibility(name));

                if (search.Count > 0)
                {
                    result.Add(new SearchResultDto()
                    {
                        pharmacySystem = pharmacySystem, drugs = new List <DrugDto>(search)
                    });
                }
            }
            _adapterContext.RemoveAdapter();
            ViewBag.SearchBox = name;
            return(View(result));
        }
예제 #2
0
        public async Task <IActionResult> Index()
        {
            PrescriptionView view = new PrescriptionView();

            view.patients = await _prescriptionService.GetAllPatients();

            view.pharmacySystems = await _pharmacySystemService.GetAll();

            return(View(view));
        }
        public async Task <IActionResult> Index(DateRangeDTO dateRangeDto)
        {
            DateRange        dateRange        = new DateRange(dateRangeDto.From, dateRangeDto.To);
            PushSubscription pushSubscription = new PushSubscription()
            {
                Endpoint = Request.Form["PushEndpoint"], P256DH = Request.Form["PushP256DH"], Auth = Request.Form["PushAuth"]
            };
            PushPayload pushPayload = new PushPayload();

            var reports = await _drugService.GetDrugConsuption(dateRange);

            if (reports == null)
            {
                pushPayload.Title   = "Unsuccess";
                pushPayload.Message = "Comunication error!";
                _pushNotificationService.SendNotification(pushSubscription, pushPayload);

                return(RedirectToAction("Index"));
            }
            if (reports.Count == 0)
            {
                pushPayload.Title   = "Unsuccess";
                pushPayload.Message = "Nothing found in given data range!";
                _pushNotificationService.SendNotification(pushSubscription, pushPayload);

                return(RedirectToAction("Index"));
            }
            var json           = JsonConvert.SerializeObject(reports, Formatting.Indented);
            var reportFileName = $"{dateRange.From:yyyy-MM-dd}-to-{dateRange.To:yyyy-MM-dd}-report.json";
            var reportFilePath = "Resources";

            try
            {
                System.IO.File.WriteAllText(Path.Combine(reportFilePath, reportFileName), json);
            }
            catch (Exception dnfe)
            {
                Console.WriteLine(dnfe);

                pushPayload.Title   = "Unsuccess";
                pushPayload.Message = "Error occured while creating report file!";
                _pushNotificationService.SendNotification(pushSubscription, pushPayload);

                return(RedirectToAction("Index"));
            }
            var pharmacySystems = await _pharmacySystemService.GetAll();

            foreach (var ps in pharmacySystems)
            {
                if (_adapterContext.SetPharmacySystemAdapter(ps) == null)
                {
                    continue;
                }

                if (_adapterContext.PharmacySystemAdapter.SendDrugConsumptionReport(reportFilePath, reportFileName))
                {
                    pushPayload.Title   = "Success";
                    pushPayload.Message = "Report successfully created and uploaded to " + ps.Name + "!";
                }
                else
                {
                    pushPayload.Title   = "Unsuccess";
                    pushPayload.Message = "Report upload to " + ps.Name + " unsuccessfull!";
                }
                _pushNotificationService.SendNotification(pushSubscription, pushPayload);
            }

            return(RedirectToAction("Index"));
        }
 public async Task <IActionResult> Index()
 {
     return(View(await _pharmacySystemService.GetAll()));
 }