예제 #1
0
        public async Task <NotiViewModel> GetNotiListAsync(string last_id, string language)
        {
            var data = new NotiViewModel();

            data.message = new messageModel();
            try
            {
                var userId = JwtHelper.GetUserIdFromToken(HttpContext);
                if (String.IsNullOrEmpty(userId))
                {
                    throw new Exception("Unauthorized Access");
                }
                using (var context = new StandardcanContext())
                {
                    var jsonData = JsonConvert.SerializeObject(new
                    {
                        last_id = last_id,
                        emp_id  = userId,
                        lang    = language
                    });
                    SystemLog systemLog = new SystemLog()
                    {
                        module   = "api/Noti/GetNotiList",
                        data_log = jsonData
                    };
                    await _systemLogService.InsertSystemLogAsync(systemLog);

                    SqlParameter noti_id = new SqlParameter("last_id", last_id ?? "");
                    SqlParameter emp_id  = new SqlParameter("emp_id", userId ?? "");
                    SqlParameter lang    = new SqlParameter("lang", language ?? "");

                    var spData = context.SpMbNotiList.FromSqlRaw("sp_mb_noti_list @emp_id, @last_id, @lang", emp_id, noti_id, lang).ToList();
                    data.content = new List <NoticontentViewModel>();
                    foreach (var item in spData)
                    {
                        NoticontentViewModel news = new NoticontentViewModel();
                        news.id      = item.id;
                        news.type    = item.type;
                        news.url_img = item.url_img;
                        news.title   = item.title;
                        news.detail  = item.detail;
                        news.time    = item.time;
                        data.content.Add(news);
                    }
                    data.message.status = "1";
                    data.message.msg    = "Success";
                }
            }
            catch (Exception ex)
            {
                data.message.status = "2";
                data.message.msg    = ex.Message;
            }
            return(data);
        }
예제 #2
0
        //public NotiTimeFrameViewModel scheduleNotis(DateTime date, int doctorid, string TimeFrame)
        //{
        //    using(var ctx = new CaremeDBContext())
        //    {
        //        var day = date.DayOfWeek.ToString();
        //        DateTime? combined = null;

        //        List<tbSchedule> schedules = ctx.tbSchedules.Where(a => a.IsDeleted != true
        //                          && a.DoctorID == doctorid).Where(daysQuery(day)).ToList();
        //        List<NotiViewModel> NotiList = new List<NotiViewModel>();
        //        foreach (var item in schedules)
        //        {
        //            combined = HelperExtension.getCombinedDateTime(date, item.Fromtime);
        //            var appointments = ctx.tbAppointments.Where(a => a.IsDeleted != true
        //                                        && a.DoctorId == item.DoctorID
        //                                        && a.HospitalId == item.HospitalID && a.Day == day
        //                                        && a.AppointmentDateTime == combined);

        //            NotiViewModel notiMD = new NotiViewModel();
        //            notiMD.scheduleID = item.ID;
        //            notiMD.AppointmentDateTime = combined ?? date;
        //            notiMD.hospitalID = item.HospitalID ?? 0;
        //            notiMD.hospitalName = item.HospitalName;
        //            notiMD.patientCount = appointments.Count();
        //            if (notiMD.patientCount > 0)
        //            {
        //                notiMD.LastActivtBookedTime = appointments.OrderByDescending(a => a.Accesstime)
        //                                       .FirstOrDefault().Accesstime ?? date;
        //            }

        //            NotiList.Add(notiMD);
        //        }
        //        NotiTimeFrameViewModel NotiObj = new NotiTimeFrameViewModel();
        //        if(schedules.Count > 0)
        //        {
        //            NotiObj.NotiList = NotiList;
        //            NotiObj.Timeframe = TimeFrame;
        //        }
        //        return NotiObj;
        //    }
        //}


        public NotiTimeFrameViewModel scheduleNotis(DateTime date, int doctorid, string TimeFrame)
        {
            using (var ctx = new CaremeDBContext())
            {
                date = date.Date;
                var      day      = date.DayOfWeek.ToString();
                DateTime?combined = null;

                //List<tbSchedule> schedules = ctx.tbSchedules.Where(a => a.IsDeleted != true
                //                  && a.DoctorID == doctorid).Where(daysQuery(day)).ToList();
                var dateto = date.AddDays(1).Date;


                List <tbScheduleData> schedules = ctx.tbScheduleDatas.Where(a => a.IsDeleted != true &&
                                                                            a.DoctorID == doctorid && a.AppointmentDatetime >= date && a.AppointmentDatetime <= dateto).ToList();

                List <NotiViewModel> NotiList = new List <NotiViewModel>();
                foreach (var item in schedules)
                {
                    //combined = HelperExtension.getCombinedDateTime(date, item.Fromtime);
                    var appointments = ctx.tbAppointments.Where(a => a.IsDeleted != true &&
                                                                a.DoctorId == item.DoctorID &&
                                                                a.HospitalId == item.HospitalID &&
                                                                a.AppointmentDateTime == item.AppointmentDatetime);

                    NotiViewModel notiMD = new NotiViewModel();
                    notiMD.scheduleID          = item.ID;
                    notiMD.AppointmentDateTime = item.AppointmentDatetime ?? date;
                    notiMD.hospitalID          = item.HospitalID ?? 0;
                    notiMD.hospitalName        = item.HospitalName;
                    notiMD.patientCount        = appointments.Count();
                    notiMD.MaxPatientCount     = item.MaxPatientCount ?? 0;
                    notiMD.IsLimited           = item.IsLimited;
                    notiMD.IsStopped           = item.IsStopped;

                    if (notiMD.patientCount > 0)
                    {
                        notiMD.LastActivtBookedTime = appointments.OrderByDescending(a => a.Accesstime)
                                                      .FirstOrDefault().Accesstime ?? date;
                    }

                    NotiList.Add(notiMD);
                }
                NotiTimeFrameViewModel NotiObj = new NotiTimeFrameViewModel();
                if (schedules.Count > 0)
                {
                    NotiObj.NotiList  = NotiList;
                    NotiObj.Timeframe = TimeFrame;
                }
                return(NotiObj);
            }
        }
예제 #3
0
        public PartialViewResult NotificationSection(string username)
        {
            NotiViewModel noti = new NotiViewModel();

            if (username != null)
            {
                List <Notification> listNotification = _service.getAllNotification(User.Identity.GetUserId());
                foreach (Notification notification in listNotification)
                {
                    NotificationViewModel notificationViewModel = new NotificationViewModel();
                    ApplicationUser       userT = new ApplicationUser();
                    userT = _service.GetUserById(notification.Id_User);
                    FieldHelper.CopyNotNullValue(notificationViewModel, userT);
                    FieldHelper.CopyNotNullValue(notificationViewModel, notification);
                    noti.ListNotification.Add(notificationViewModel);
                }
                noti.ListNotification.OrderBy(x => x.CreatedDate);
            }
            return(PartialView("_Noti", noti));
        }