Esempio n. 1
0
        /// <summary>
        /// Create device
        /// </summary>
        /// <param name="device"></param>
        /// <param name="user">This parameter is provided so that we can know which user created device.</param>
        /// <returns></returns>
        public int CreateDevice(CreateDeviceDomain device, UserDomain user)
        {
            if (device == null || user == null)
            {
                throw new NsiArgumentNullException(DeviceMessages.DeviceInvalidArgument);
            }
            DeviceStatus newStatus = _context.DeviceStatus.Where(x => x.Name == "New").FirstOrDefault();

            if (newStatus == null)
            {
                throw new NsiNotFoundException(DeviceMessages.InvalidDeviceStatus);
            }

            if (!_context.DeviceType.Any(x => x.DeviceTypeId == device.DeviceTypeId))
            {
                throw new NsiArgumentException(DeviceTypeMessages.DeviceTypeInvalidId);
            }

            if (!_context.DeviceType.Any(x => x.DeviceTypeId == device.DeviceTypeId && x.IsActive))
            {
                throw new NsiArgumentException(DeviceTypeMessages.DeviceTypeNotActive);
            }

            var deviceDb = new Device().FromDomainModel(device, user);

            deviceDb.DeviceStatusId = newStatus.DeviceStatusId;

            _context.Device.Add(deviceDb);
            _context.SaveChanges();

            return(deviceDb.DeviceId);
        }
Esempio n. 2
0
        public int AddDevicePing(int tenantId, DevicePingDomain device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device cannot be null");
            }

            if (tenantId <= 0)
            {
                throw new NsiArgumentException("Invalid tenant ID");
            }

            device.TenantId = tenantId;

            var devicePingDb = new NSI.EF.DevicePing().FromDomainModel(device);

            _context.DevicePing.Add(devicePingDb);

            // Set devicePingId to newly added record id
            device.DevicePropertyValues.ForEach(dpv => {
                dpv.DevicePingId = devicePingDb.DevicePingId;
                dpv.TenantId     = tenantId;
            });

            device.DevicePropertyValues.ForEach(devicePropertyValue =>
            {
                _context.DevicePropertyValue.Add((new NSI.EF.DevicePropertyValue()).FromDomainModel(devicePropertyValue));
            });

            _context.SaveChanges();

            return(devicePingDb.DevicePingId);
        }
Esempio n. 3
0
        public void UpdateIncidentSettlement(IncidentSettlementDomain incident)
        {
            var incidentSettlementDb = _context.IncidentSettlement.FirstOrDefault(x => x.IncidentSettlementId == incident.IncidentSettlementId);

            incidentSettlementDb.FromDomainModel(incident);
            _context.SaveChanges();
        }
Esempio n. 4
0
        /// <summary>
        /// Add a new attachment
        /// </summary>
        /// <param name="attachment"></param>
        /// <returns></returns>
        public int Add(AttachmentDomain attachment)
        {
            var attachmentDb = new Attachment().FromDomainModel(attachment);

            _context.Attachment.Add(attachmentDb);
            _context.SaveChanges();
            return(attachmentDb.AttachmentId);
        }
Esempio n. 5
0
        /// <summary>
        /// Add a new language
        /// </summary>
        /// <param name="language"></param>
        /// <returns></returns>
        public int Add(LanguageDomain language)
        {
            var languageDb = new Language().FromDomainModel(language);

            _context.Language.Add(languageDb);
            _context.SaveChanges();
            return(languageDb.LanguageId);
        }
Esempio n. 6
0
        /// <summary>
        /// Add new sms
        /// </summary>
        /// <param name="sms"></param>
        /// <returns></returns>
        public int Add(SmsDomain sms)
        {
            var smsDb = new Sms().FromDomainModel(sms);

            _context.Sms.Add(smsDb);
            _context.SaveChanges();
            return(smsDb.SmsId);
        }
Esempio n. 7
0
        /// <summary>
        /// Adds new module to the database
        /// </summary>
        /// <param name="module">Module information to be added. Instance of <see cref="ModuleDomain"/></param>
        /// <returns>ModuleId of the newly created module</returns>
        public int Add(ModuleDomain module)
        {
            var moduleDb = new Module().FromDomainModel(module);

            _context.Module.Add(moduleDb);
            _context.SaveChanges();
            return(moduleDb.ModuleId);
        }
Esempio n. 8
0
        /// <summary>
        /// Add a notification user
        /// </summary>
        /// <param name="notificationUser"></param>
        /// <returns></returns>
        public int Add(NotificationUserDomain notificationUser)
        {
            var notificationDb = new NotificationUser().FromDomainModel(notificationUser);

            _context.NotificationUser.Add(notificationDb);
            _context.SaveChanges();
            return(notificationDb.NotificationUserId);
        }
Esempio n. 9
0
        /// <summary>
        /// Adds new user to the database
        /// </summary>
        /// <param name="user">User information to be added. Instance of <see cref="ModuleDomain"/></param>
        /// <returns>UserId of the newly created user</returns>
        public int AddUser(UserDomain user)
        {
            var userDb = new UserInfo().FromDomainModel(user);

            _context.UserInfo.Add(userDb);
            _context.SaveChanges();
            return(userDb.UserInfoId);
        }
Esempio n. 10
0
        public int AddIncidentWorkOrder(IncidentWorkOrderDomain workOrder)
        {
            var incidentWorkOrderDb = new WorkOrder().FromDomainModel(workOrder);

            _context.WorkOrder.Add(incidentWorkOrderDb);
            _context.SaveChanges();
            return(incidentWorkOrderDb.WorkOrderId);
        }
Esempio n. 11
0
        /// <summary>
        /// Adds a single email recipient to db
        /// </summary>
        /// <param name="emailRecipient"><see cref="EmailRecipientDomain"/></param>
        /// <returns></returns>
        public int Add(EmailRecipientDomain emailRecipient)
        {
            var emailRecipientDb = new EmailRecipient().FromDomainModel(emailRecipient);

            _context.EmailRecipient.Add(emailRecipientDb);
            _context.SaveChanges();
            return(emailRecipientDb.EmailRecipientId);
        }
Esempio n. 12
0
        public int AddIncidentType(IncidentTypeDomain incidentType)
        {
            var incidentTypeDb = new IncidentType().FromDomainModel(incidentType);

            _context.IncidentType.Add(incidentTypeDb);
            _context.SaveChanges();
            return(incidentTypeDb.IncidentTypeId);
        }
Esempio n. 13
0
        /// <summary>
        /// Adds new tenant to the database
        /// </summary>
        /// <param name="tenant">Tenant information to be added. Instance of <see cref="TenantDomain"/></param>
        /// <returns>TenantId of the newly created tenant</returns>
        public int Add(TenantDomain tenant)
        {
            var tenantDb = new Tenant().FromDomainModel(tenant);

            _context.Tenant.Add(tenantDb);
            _context.SaveChanges();
            return(tenantDb.TenantId);
        }
Esempio n. 14
0
        /// <summary>
        /// Adds new role to the database
        /// </summary>
        /// <param name="role">Role information to be added. Instance of <see cref="RoleDomain"/></param>
        /// <returns>RoleId of the newly created role</returns>
        public int Add(RoleDomain role)
        {
            var roleDb = new Role().FromDomainModel(role);

            _context.Role.Add(roleDb);
            _context.SaveChanges();
            return(roleDb.RoleId);
        }
Esempio n. 15
0
        /// <summary>
        /// Adds new rolePermission to the database
        /// </summary>
        /// <param name="rolePermission">RolePermission information to be added. Instance of <see cref="RolePermissionDomain"/></param>
        /// <returns>RolePermissionID of the newly created rolePermission</returns>
        public int Add(RolePermissionDomain rolePermission)
        {
            var rolePermissionDb = new RolePermission().FromDomainModel(rolePermission);

            _context.RolePermission.Add(rolePermissionDb);
            _context.SaveChanges();
            return(rolePermissionDb.RolePermissionId);
        }
Esempio n. 16
0
        /// <summary>
        /// Add a web notification
        /// </summary>
        /// <param name="domain"></param>
        /// <returns></returns>
        public int Add(WebNotificationDomain domain)
        {
            WebNotification webNotification = new WebNotification().FromDomainModel(domain);

            _context.WebNotification.Add(webNotification);
            _context.SaveChanges();
            return(webNotification.WebNotificationId);
        }
Esempio n. 17
0
        /// <summary>
        /// Adds new permission  to the database
        /// </summary>
        /// <param name="permission">Permission information to be added. Instance of <see cref="PermissionDomain"/></param>
        /// <returns>PermissionId of the newly created permission</returns>
        public int Add(PermissionDomain permission)
        {
            var permissionDb = new Permission().FromDomainModel(permission);

            _context.Permission.Add(permissionDb);
            _context.SaveChanges();
            return(permissionDb.PermissionId);
        }
Esempio n. 18
0
        /// <summary>
        /// Adds new roleMmber to the database
        /// </summary>
        /// <param name="roleMember">RoleMmber information to be added. Instance of <see cref="RoleMemberDomain"/></param>
        /// <returns>RoleMemberID of the newly created module</returns>
        public int Add(RoleMemberDomain roleMember)
        {
            var roleMemberDb = new RoleMember().FromDomainModel(roleMember);

            _context.RoleMember.Add(roleMemberDb);
            _context.SaveChanges();
            return(roleMemberDb.RoleMemberId);
        }
Esempio n. 19
0
        /// <summary>
        /// Adds new templateversion
        /// </summary>
        /// <returns></returns>
        public int Add(TemplateVersionDomain templateVersion)
        {
            var templateVersionDb = new TemplateVersion().FromDomainModel(templateVersion);

            _context.TemplateVersion.Add(templateVersionDb);
            _context.SaveChanges();
            return(templateVersionDb.TemplateVersionId);
        }
Esempio n. 20
0
        /// <summary>
        /// Add a new email message
        /// </summary>
        /// <param name="emailMessage"><see cref="EmailMessageDomain"/></param>
        /// <returns></returns>
        public int Add(EmailMessageDomain emailMessage)
        {
            var emailMessageDb = new EmailMessage().FromDomainModel(emailMessage);

            _context.EmailMessage.Add(emailMessageDb);
            _context.SaveChanges();
            return(emailMessageDb.EmaiMessagelId);
        }
Esempio n. 21
0
        /// <summary>
        /// Add a notification type
        /// </summary>
        /// <param name="domain"></param>
        /// <returns></returns>
        public int Add(NotificationTypeDomain domain)
        {
            NotificationType notificationType = new NotificationType().FromDomainModel(domain);

            _context.NotificationType.Add(notificationType);
            _context.SaveChanges();
            return(notificationType.NotificationTypeId);
        }
Esempio n. 22
0
        /// <summary>
        /// Add a single notification status
        /// </summary>
        /// <param name="notificationStatus"></param>
        /// <returns></returns>
        public int AddNotificationStatus(NotificationStatusDomain notificationStatus)
        {
            var notificationStatusDb = new NotificationStatus().FromDomainModel(notificationStatus);

            _context.NotificationStatus.Add(notificationStatusDb);
            _context.SaveChanges();
            return(notificationStatusDb.NotificationStatusId);
        }
Esempio n. 23
0
        /// <summary>
        /// Adds a new email recipient type to the database
        /// </summary>
        /// <param name="emailRecipientType">Email recipient type information to be added. Instance of <see cref="EmailRecipientTypeDomain"/></param>
        /// <returns>EmailRecipientTypeId of the created email recipient type</returns>
        public int Add(EmailRecipientTypeDomain emailRecipientType)
        {
            var emailRecipientTypeDb = new EmailRecipientType().FromDomainModel(emailRecipientType);

            _context.EmailRecipientType.Add(emailRecipientTypeDb);
            _context.SaveChanges();
            return(emailRecipientTypeDb.EmailRecipientTypeId);
        }
Esempio n. 24
0
        /// <summary>
        /// Add a notification
        /// </summary>
        /// <param name="notification"></param>
        /// <returns></returns>
        public int Add(NotificationDomain notification)
        {
            var notificationDb = new Notification().AddFromDomainModel(notification);

            _context.Notification.Add(notificationDb);
            _context.SaveChanges();
            return(notificationDb.NotificationId);
        }
Esempio n. 25
0
        public int AddIncidentStatus(IncidentStatusDomain incidentStatus)
        {
            var incidentStatusDb = new IncidentStatus().FromDomainModel(incidentStatus);

            _context.IncidentStatus.Add(incidentStatusDb);
            _context.SaveChanges();
            return(incidentStatusDb.IncidentStatusId);
        }
Esempio n. 26
0
        /// <summary>
        /// Adds new template
        /// </summary>
        /// <returns></returns>
        public int Add(TemplateDomain template)
        {
            if (!_context.Folder.Any(x => x.FolderId == template.FolderId))
            {
                throw new NsiArgumentException(TemplateManagementMessages.FolderInvalidId);
            }
            var templateDb = new Template().FromDomainModel(template);

            _context.Template.Add(templateDb);
            _context.SaveChanges();
            return(templateDb.TemplateId);
        }
Esempio n. 27
0
        public int AddIncidentPriority(IncidentPriorityDomain priority)
        {
            if (priority == null)
            {
                throw new NsiArgumentException(ExceptionMessages.ArgumentException);
            }
            var incidentPriorityDb = new Priority().FromDomainModel(priority);

            _context.Priority.Add(incidentPriorityDb);
            _context.SaveChanges();
            return(incidentPriorityDb.PriorityId);
        }
Esempio n. 28
0
        public int AddRule(AddRuleDomain rule, UserDomain user)
        {
            // Validate conditions
            foreach (var condition in rule.Conditions)
            {
                var device = _context.Device.Find(condition.DeviceId);

                if (device == null)
                {
                    throw new NsiArgumentException("Device does not exist.");
                }

                if (device.DeviceType.Property.First(property => property.PropertyId == condition.ParameterId) == null)
                {
                    throw new NsiArgumentException("Parameter is not defined for the selected device.");
                }
            }

            // Validate actions
            foreach (var action in rule.Actions)
            {
                var device = _context.Device.Find(action.DeviceId);

                if (device == null)
                {
                    throw new NsiArgumentException("Device does not exist.");
                }

                if (device.DeviceType.Action.First(current => current.ActionId == action.ActionId) == null)
                {
                    throw new NsiArgumentException("Action is not defined for the selected device.");
                }
            }

            // Create everything
            var ruleObject = new Rule().FromDomainModel(rule, user);

            foreach (var condition in rule.Conditions)
            {
                ruleObject.RuleCondition.Add(new RuleCondition().FromDomainModel(condition, user));
            }

            foreach (var action in rule.Actions)
            {
                ruleObject.RuleAction.Add(new RuleAction().FromDomainModel(action, user));
            }

            _context.Rule.Add(ruleObject);
            _context.SaveChanges();

            return(ruleObject.RuleId);
        }
Esempio n. 29
0
        public int CreateStorageType(StorageTypeDomain storageType)
        {
            if (storageType == null)
            {
                throw new NsiArgumentException(StorageTypeMessages.StorageTypeInvalidArgument);
            }

            var storageTypeDb = new StorageType().FromDomainModel(storageType);

            _context.StorageType.Add(storageTypeDb);
            _context.SaveChanges();

            return(storageTypeDb.StorageTypeId);
        }
Esempio n. 30
0
        public int CreateFileType(FileTypeDomain fileType)
        {
            if (fileType == null)
            {
                throw new NsiArgumentException(FileTypeMessages.FileTypeInvalidArgument);
            }

            var fileTypeDb = new FileType().FromDomainModel(fileType);

            _context.FileType.Add(fileTypeDb);
            _context.SaveChanges();

            return(fileTypeDb.FileTypeId);
        }