예제 #1
0
        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);
        }
예제 #2
0
        public bool SaveUser(UserDto user)
        {
            var users = _DBContext.Set <UserExtention>();
            var roles = _DBContext.Set <Domain.Entities.Role>();

            var existing = users.Include(u => u.Roles).Include(u => u.Hospital).Include(u => u.Department).FirstOrDefault(u => u.UniqueID == user.UniqueID);

            if (existing == null)
            {
                if (user.DepartmentID == null)
                {
                    // set default department
                    var data = _RisProContext.Set <User2Domain>().FirstOrDefault(u => u.UniqueID == user.UniqueID);
                    if (data != null)
                    {
                        var name = data.Department;
                        if (!String.IsNullOrEmpty(name))
                        {
                            var department = _DBContext.Set <Department>().FirstOrDefault(d => d.Name == name);
                            if (department == null)
                            {
                                // add department
                                department = new Department()
                                {
                                    UniqueID = Guid.NewGuid().ToString(),
                                    Name     = name
                                };
                                _DBContext.Set <Department>().Add(department);
                            }
                            user.DepartmentID = department.UniqueID;
                        }
                    }
                }
                //add
                var newUserExtention = Mapper.Map <UserDto, UserExtention>(user);
                newUserExtention.LastStatus = "ris.consultation.requests";
                users.Attach(newUserExtention);
                users.Add(newUserExtention);
                existing = newUserExtention;
            }
            else
            {
                Mapper.Map(user, existing);
            }

            if (user.IsMobileChanged)
            {
                UpdateUserMobile(user);
            }

            // update roles
            existing.Roles.Clear();
            user.Roles.Select(r => roles.Find(r.UniqueID)).Where(role => role != null).ForEach(existing.Roles.Add);

            _DBContext.SaveChanges();
            return(true);
        }
예제 #3
0
        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)));
        }
예제 #4
0
        public bool SaveRole(RoleDto role)
        {
            //distinc permissions
            if (!String.IsNullOrEmpty(role.Permissions))
            {
                role.Permissions = String.Join(",", role.Permissions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Distinct());
            }

            var roles        = _DBContext.Set <Role>();
            var existingRole = roles.FirstOrDefault(r => r.UniqueID == role.UniqueID);

            if (existingRole == null)
            {
                roles.Add(Mapper.Map <RoleDto, Role>(role));
            }
            else
            {
                Mapper.Map(role, existingRole);
            }
            _DBContext.SaveChanges();
            return(true);
        }