public bool SendNotification(NotificationData notificationData) { var config = GetNotificationConfigs().FirstOrDefault(c => c.Event == notificationData.NotifyEvent); if (config != null && config.IsEnable && !String.IsNullOrWhiteSpace(config.NotifyTypes)) { var template = config.Template; var text = notificationData.Context.Translate(template); foreach (var type in config.NotifyTypes.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { _DBContext.Set <Notification>().Add(new Notification { UniqueID = Guid.NewGuid().ToString(), IsSended = false, Event = (int)notificationData.NotifyEvent, LastEditTime = DateTime.Now, LastEditUser = _LoginUserService.CurrentUserID, NotifyType = int.Parse(type), Recipients = notificationData.Recipients, PendingTime = DateTime.Now, Sender = _LoginUserService.CurrentUserID, OwnerID = notificationData.OwnerID, Text = text, }); if (!String.IsNullOrWhiteSpace(config.SendingTimes)) { //config.AdjustTime foreach (var adjustment in config.SendingTimes.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries)) { int offset; if (int.TryParse(adjustment, out offset)) { var sendingTime = notificationData.SendingTime.AddMinutes(-offset); if (sendingTime > DateTime.Now) { _DBContext.Set <Notification>().Add(new Notification { UniqueID = Guid.NewGuid().ToString(), IsSended = false, Event = (int)notificationData.NotifyEvent, LastEditTime = DateTime.Now, LastEditUser = _LoginUserService.CurrentUserID, NotifyType = int.Parse(type), Recipients = notificationData.Recipients, PendingTime = sendingTime, Sender = _LoginUserService.CurrentUserID, OwnerID = notificationData.OwnerID, Text = text, }); } } } } } _DBContext.SaveChanges(); return(true); } return(false); }
public HospitalProfileDto GetHospital(string userID) { //get hos info by userid HospitalProfile hospitalProfile = (from h in _DBContext.Set <HospitalProfile>() join o in _DBContext.Set <UserExtention>() on h.UniqueID equals o.HospitalID where o.UniqueID == userID select h).FirstOrDefault(); if (hospitalProfile != null) { return(Mapper.Map <HospitalProfile, HospitalProfileDto>(hospitalProfile)); } return(new HospitalProfileDto { UniqueID = "1" }); }
public IQueryable <User> FilterUsers(UserSearchCriteriaDto searchCriteria) { var users = _RisProContext.Set <User>().Where(u => u.DeleteMark != 1); if (!_LoginUserService.IsSystemAdmin && !searchCriteria.ShowAllUser) { var excludeUserIds = _DBContext.Set <UserExtention>() .Where(u => !String.IsNullOrEmpty(u.HospitalID) && u.HospitalID != _LoginUserService.DefaultSiteID) .Select(u => u.UniqueID).ToList(); users = users.Where(u => !excludeUserIds.Contains(u.UniqueID)); } if (!String.IsNullOrEmpty(searchCriteria.Name)) { users = users.Where(u => u.LoginName.Contains(searchCriteria.Name) || u.LocalName.Contains(searchCriteria.Name)); } var hasDep = !String.IsNullOrEmpty(searchCriteria.DepartmentID); var hasHospital = !String.IsNullOrEmpty(searchCriteria.HospitalID); var hasRole = !String.IsNullOrEmpty(searchCriteria.RoleID); var hasArea = !String.IsNullOrEmpty(searchCriteria.ProvinceName); var hasInCenter = searchCriteria.IsInCenter != null && searchCriteria.IsInCenter == 1; if (hasDep || hasHospital || hasRole || hasArea || hasInCenter) { var query = _DBContext.Set <UserExtention>().AsQueryable(); if (hasDep) { query = query.Where(u => u.DepartmentID == searchCriteria.DepartmentID); } if (hasHospital) { query = query.Where(u => u.HospitalID == searchCriteria.HospitalID); } if (hasRole) { query = query.Where(u => u.Roles.Any(r => r.UniqueID == searchCriteria.RoleID)); } if (hasArea) { //get hospital ids var queryHospital = _DBContext.Set <HospitalProfile>().Where(u => u.Province == searchCriteria.ProvinceName); if (!String.IsNullOrEmpty(searchCriteria.CityName)) { queryHospital = queryHospital.Where(u => u.City == searchCriteria.CityName); } var hospitalIds = queryHospital.Select(u => u.UniqueID).ToList(); query = query.Where(u => hospitalIds.Contains(u.HospitalID)); } if (hasInCenter) { var queryHospital = _DBContext.Set <HospitalProfile>().Where(u => u.IsConsultation == true); var hospitalIds = queryHospital.Select(u => u.UniqueID).ToList(); query = query.Where(u => hospitalIds.Contains(u.HospitalID)); } var userIds = query.Select(u => u.UniqueID).ToList(); users = users.Where(u => userIds.Contains(u.UniqueID)); } return(users); }
public void GetDictionaryByTypeTest() { var dic = MockData.Generate <ConsultationDictionary>(3, d => { d.Type = DictionaryType.ConsultationStauts; }).ToList(); _consultationContext.Set <ConsultationDictionary>().AddRange(dic); _consultationContext.SaveChanges(); var result = _service.GetDictionaryByType(1, ""); Assert.IsTrue(dic.All(d => result.Any(i => i.DictionaryID == d.DictionaryID))); }