Exemplo n.º 1
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = dbEntity.OperationTask.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(10701);
                }

                if (parseData.CompletedAt.HasValue)
                {
                    existingData.CompletedAt = (DateTime)parseData.CompletedAt;
                }

                if (parseData.RetryCounter.HasValue)
                {
                    existingData.RetryCounter = (int)parseData.RetryCounter;
                }

                if (parseData.TaskStatus != null)
                {
                    existingData.TaskStatus = parseData.TaskStatus;
                }

                if (parseData.TaskLog != null)
                {
                    existingData.TaskLog = parseData.TaskLog;
                }

                existingData.UpdatedAt = DateTime.UtcNow;
                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 2
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = dbEntity.MessageMandatoryElementDef.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(10701);
                }

                if (parseData.ElementName != null)
                {
                    existingData.ElementName = parseData.ElementName;
                }

                if (parseData.ElementDataType != null)
                {
                    existingData.ElementDataType = parseData.ElementDataType;
                }

                if (parseData.Description != null)
                {
                    existingData.Description = parseData.Description;
                }

                if (parseData.MandatoryFlag.HasValue)
                {
                    existingData.MandatoryFlag = (bool)parseData.MandatoryFlag;
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 3
0
        public void Update(int code, Format_Update parseModel)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = dbEntity.PermissionCatalog.Find(code);
                if (existingData == null)
                {
                    throw new CDSException(11701);
                }

                if (parseModel.Name != null)
                {
                    existingData.Name = parseModel.Name;
                }

                if (parseModel.Description != null)
                {
                    existingData.Description = parseModel.Description;
                }

                if (parseModel.Code.HasValue)
                {
                    existingData.Code = (int)parseModel.Code;
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 4
0
        public void UpdateByKey(int key, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = dbEntity.WidgetClass.Find(key);
                if (existingData == null)
                {
                    throw new CDSException(12301);
                }

                if (parseData.Name != null)
                {
                    existingData.Name = parseData.Name;
                }

                if (parseData.Level != null)
                {
                    existingData.Level = parseData.Level;
                }

                if (parseData.PhotoURL != null)
                {
                    existingData.PhotoURL = parseData.PhotoURL;
                }

                if (parseData.AllowMultipleAppearOnBoard.HasValue)
                {
                    existingData.AllowMultipleAppearOnBoard = (bool)parseData.AllowMultipleAppearOnBoard;
                }
                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 5
0
        public void UpdateAllByEventRuleCatalogId(int EventRuleCatalogId, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                //Delete all existing ruleItem
                List <EventRuleItem> existingDataList = (from c in dbEntity.EventRuleItem
                                                         where c.EventRuleCatalogId == EventRuleCatalogId
                                                         select c).ToList <EventRuleItem>();
                dbEntity.EventRuleItem.RemoveRange(existingDataList);
                dbEntity.SaveChanges();

                if (parseData.Rule.Count > 0)
                {
                    foreach (var rule in parseData.Rule)
                    {
                        dbEntity.EventRuleItem.Add(new EventRuleItem()
                        {
                            EventRuleCatalogId     = EventRuleCatalogId,
                            Ordering               = rule.Ordering,
                            MessageElementParentId = rule.MessageElementParentId,
                            MessageElementId       = rule.MessageElementId,
                            EqualOperation         = rule.EqualOperation,
                            Value            = rule.Value,
                            BitWiseOperation = rule.BitWiseOperation
                        });
                    }
                    dbEntity.SaveChanges();
                }
            }
        }
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingIoTDeviceCustomizedConfiguration = dbEntity.IoTDeviceCustomizedConfiguration.Find(id);
                if (existingIoTDeviceCustomizedConfiguration == null)
                {
                    throw new CDSException(10701);
                }

                if (parseData.Name != null)
                {
                    existingIoTDeviceCustomizedConfiguration.Name = parseData.Name;
                }

                if (parseData.DataType != null)
                {
                    existingIoTDeviceCustomizedConfiguration.DataType = parseData.DataType;
                }

                if (parseData.Description != null)
                {
                    existingIoTDeviceCustomizedConfiguration.Description = parseData.Description;
                }

                if (parseData.DefaultValue != null)
                {
                    existingIoTDeviceCustomizedConfiguration.DefaultValue = parseData.DefaultValue;
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 7
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = dbEntity.MessageElement.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(10701);
                }

                if (parseData.ElementName != null)
                {
                    existingData.ElementName = parseData.ElementName;
                }

                if (parseData.ElementDataType != null)
                {
                    existingData.ElementDataType = parseData.ElementDataType;
                }

                if (parseData.MandatoryFlag.HasValue)
                {
                    existingData.MandatoryFlag = (bool)parseData.MandatoryFlag;
                }

                //ChildMessageCatalogID may be null or integer
                existingData.ChildMessageCatalogID = parseData.ChildMessageCatalogID;

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 8
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = dbEntity.MessageCatalog.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(10701);
                }

                if (parseData.Name != null)
                {
                    existingData.Name = parseData.Name;
                }

                if (parseData.Description != null)
                {
                    existingData.Description = parseData.Description;
                }

                if (parseData.MonitorFrequenceInMinSec.HasValue)
                {
                    existingData.MonitorFrequenceInMinSec = (int)parseData.MonitorFrequenceInMinSec;
                }

                if (parseData.ChildMessageFlag.HasValue)
                {
                    existingData.ChildMessageFlag = (bool)parseData.ChildMessageFlag;
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 9
0
        public void Update(int id, Format_Update dataModel)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingSuperAdmin = dbEntity.SuperAdmin.Find(id);
                if (existingSuperAdmin == null)
                {
                    throw new CDSException(10701);
                }

                if (dataModel.FirstName != null)
                {
                    existingSuperAdmin.FirstName = dataModel.FirstName;
                }

                if (dataModel.LastName != null)
                {
                    existingSuperAdmin.LastName = dataModel.LastName;
                }

                if (dataModel.DeletedFlag.HasValue)
                {
                    existingSuperAdmin.DeletedFlag = (bool)dataModel.DeletedFlag;
                }

                existingSuperAdmin.UpdatedAt = DateTime.UtcNow;
                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 10
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = dbEntity.DeviceCommandCatalog.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(10403);
                }

                existingData.Name    = parseData.Name;
                existingData.Method  = parseData.Method;
                existingData.Content = parseData.Content;

                try
                {
                    dbEntity.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    if (ex.InnerException.InnerException.Message.Contains("Cannot insert duplicate key"))
                    {
                        throw new CDSException(10404);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
        }
Exemplo n.º 11
0
        public void Update(int id, Format_Update parseData, int companyId)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                //ExternalDashboard existingData = dbEntity.ExternalDashboard.Find(id);
                ExternalDashboard existingData = (from c in dbEntity.ExternalDashboard
                                                  where c.Id == id && c.CompanyId == companyId
                                                  select c).SingleOrDefault <ExternalDashboard>();
                if (existingData == null)
                {
                    throw new CDSException(10502);
                }

                if (parseData.Name != null)
                {
                    existingData.Name = parseData.Name;
                }

                if (parseData.Ordering > 0)
                {
                    existingData.Ordering = parseData.Ordering;
                }

                if (parseData.URL != null)
                {
                    existingData.URL = parseData.URL;
                }

                dbEntity.Entry(existingData).State = EntityState.Modified;
                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 12
0
        public void UpdateByEquipmentClassId(int equipmentClassId, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = from c in dbEntity.EquipmentClassMessageCatalog
                                   where c.EquipmentClassID == equipmentClassId
                                   select c;
                dbEntity.EquipmentClassMessageCatalog.RemoveRange(existingData);

                if (parseData.MessageCatalogId != null)
                {
                    List <EquipmentClassMessageCatalog> newDataList = new List <EquipmentClassMessageCatalog>();
                    foreach (int messageCatalogId in parseData.MessageCatalogId)
                    {
                        newDataList.Add(new EquipmentClassMessageCatalog()
                        {
                            EquipmentClassID = equipmentClassId,
                            MessageCatalogID = messageCatalogId
                        });
                    }
                    dbEntity.EquipmentClassMessageCatalog.AddRange(newDataList);
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 13
0
        public void Update(int userRoleId, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                UserRole existingData = dbEntity.UserRole.Find(userRoleId);
                if (existingData == null)
                {
                    throw new CDSException(12103);
                }

                if (existingData.Name != parseData.Name)
                {
                    try
                    {
                        existingData.Name = parseData.Name;
                        dbEntity.SaveChanges();
                    }
                    catch
                    {
                        throw new CDSException(12104);
                    }
                }

                //adjust user role's permission
                UserRolePermissionModel model = new UserRolePermissionModel();
                model.DeleteAllByUserRoleId(userRoleId);

                if (parseData.PermissionCatalogCode != null)
                {
                    model.CreateManyByUserRoleId(userRoleId, parseData.PermissionCatalogCode);
                }
            }
        }
Exemplo n.º 14
0
        public void Update(int id, Format_Update factory)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                Factory existingFactory = dbEntity.Factory.Find(id);
                if (existingFactory == null)
                {
                    throw new CDSException(10601);
                }

                if (factory.Name != null)
                {
                    existingFactory.Name = factory.Name;
                }

                if (factory.Description != null)
                {
                    existingFactory.Description = factory.Description;
                }

                if (factory.Latitude.HasValue)
                {
                    existingFactory.Latitude = factory.Latitude;
                }

                if (factory.Longitude.HasValue)
                {
                    existingFactory.Longitude = factory.Longitude;
                }

                if (factory.TimeZone.HasValue)
                {
                    existingFactory.TimeZone = Convert.ToInt32(factory.TimeZone);
                }

                if (factory.CultureInfoId != null)
                {
                    existingFactory.CultureInfo = factory.CultureInfoId;
                }

                dbEntity.Entry(existingFactory).State = EntityState.Modified;
                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 15
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                DeviceCertificate existingData = dbEntity.DeviceCertificate.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(10401);
                }

                if (parseData.Name != null)
                {
                    existingData.Name = parseData.Name;
                }

                if (parseData.KeyFile != null)
                {
                    existingData.KeyFile = parseData.KeyFile;
                }

                if (parseData.CertFile != null)
                {
                    existingData.CertFile = parseData.CertFile;
                }

                if (parseData.Thumbprint != null)
                {
                    existingData.Thumbprint = parseData.Thumbprint;
                }

                if (parseData.Password != null)
                {
                    existingData.Password = parseData.Password;
                }

                if (parseData.ExpiredAt != null)
                {
                    existingData.ExpiredAt = parseData.ExpiredAt;
                }

                dbEntity.Entry(existingData).State = EntityState.Modified;
                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 16
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                SystemConfiguration existingData = dbEntity.SystemConfiguration.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(11901);
                }

                if (parseData.Group != null)
                {
                    existingData.Group = parseData.Group;
                }

                if (parseData.Key != null)
                {
                    existingData.Key = parseData.Key;
                }

                if (parseData.Value != null)
                {
                    existingData.Value = parseData.Value;
                }

                dbEntity.Entry(existingData).State = EntityState.Modified;
                try
                {
                    dbEntity.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    if (ex.InnerException.InnerException.Message.Contains("Cannot insert duplicate key"))
                    {
                        throw new CDSException(11902);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
        }
Exemplo n.º 17
0
        public void Update(int id, Format_Update parseData, int companyId)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                //MetaDataDefination existingData = dbEntity.MetaDataDefination.Find(id);
                MetaDataDefination existingData = (from c in dbEntity.MetaDataDefination
                                                   where c.Id == id && c.CompanyId == companyId
                                                   select c).SingleOrDefault <MetaDataDefination>();
                if (existingData == null)
                {
                    throw new CDSException(11301);
                }

                if (parseData.EntityType != null)
                {
                    existingData.EntityType = parseData.EntityType;
                }

                if (parseData.ObjectName != null)
                {
                    existingData.ObjectName = parseData.ObjectName;
                }

                dbEntity.Entry(existingData).State = EntityState.Modified;
                try
                {
                    dbEntity.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    if (ex.InnerException.InnerException.Message.Contains("Cannot insert duplicate key"))
                    {
                        throw new CDSException(11302);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
        }
Exemplo n.º 18
0
        public void Update(int id, Format_Update dataModel)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingDeviceType = dbEntity.DeviceType.Find(id);
                if (existingDeviceType == null)
                {
                    throw new CDSException(10701);
                }

                if (dataModel.Name != null)
                {
                    existingDeviceType.Name = dataModel.Name;
                }

                if (dataModel.Description != null)
                {
                    existingDeviceType.Description = dataModel.Description;
                }
                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 19
0
        public void Update(int id, Format_Update dataModel)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingEmployee = dbEntity.Employee.Find(id);
                if (existingEmployee == null)
                {
                    throw new CDSException(10701);
                }

                if (dataModel.EmployeeNumber != null)
                {
                    existingEmployee.EmployeeNumber = dataModel.EmployeeNumber;
                }

                if (dataModel.FirstName != null)
                {
                    existingEmployee.FirstName = dataModel.FirstName;
                }

                if (dataModel.LastName != null)
                {
                    existingEmployee.LastName = dataModel.LastName;
                }

                if (dataModel.Lang != null)
                {
                    existingEmployee.Lang = dataModel.Lang;
                }

                if (dataModel.AdminFlag.HasValue)
                {
                    existingEmployee.AdminFlag = (bool)dataModel.AdminFlag;
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 20
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = dbEntity.EventRuleCatalog.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(10701);
                }

                if (parseData.MessageCatalogId.HasValue)
                {
                    existingData.MessageCatalogId = (int)parseData.MessageCatalogId;
                }

                if (parseData.Name != null)
                {
                    existingData.Name = parseData.Name;
                }

                if (parseData.Description != null)
                {
                    existingData.Description = parseData.Description;
                }

                if (parseData.AggregateInSec.HasValue)
                {
                    existingData.AggregateInSec = (int)parseData.AggregateInSec;
                }

                if (parseData.ActiveFlag.HasValue)
                {
                    existingData.ActiveFlag = (bool)parseData.ActiveFlag;
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 21
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = dbEntity.EquipmentClass.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(10701);
                }

                if (parseData.Name != null)
                {
                    existingData.Name = parseData.Name;
                }

                if (parseData.Description != null)
                {
                    existingData.Description = parseData.Description;
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 22
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                Application existingApplication = dbEntity.Application.Find(id);
                if (existingApplication == null)
                {
                    throw new CDSException(10102);
                }

                if (parseData.MessageTemplate != null)
                {
                    try
                    {
                        JObject.Parse(parseData.MessageTemplate);
                    }
                    catch
                    {
                        throw new CDSException(10103);
                    }
                    existingApplication.MessageTemplate = parseData.MessageTemplate;
                }

                if (parseData.Name != null)
                {
                    existingApplication.Name = parseData.Name;
                }

                if (parseData.Description != null)
                {
                    existingApplication.Description = parseData.Description;
                }

                if (parseData.TargetType != null)
                {
                    existingApplication.TargetType = parseData.TargetType;
                }

                if (parseData.Method != null)
                {
                    existingApplication.Method = parseData.Method;
                }

                if (parseData.ServiceURL != null)
                {
                    existingApplication.ServiceURL = parseData.ServiceURL;
                }

                if (parseData.AuthType != null)
                {
                    existingApplication.AuthType = parseData.AuthType;
                }

                if (parseData.AuthID != null)
                {
                    existingApplication.AuthID = parseData.AuthID;
                }

                if (parseData.AuthPW != null)
                {
                    existingApplication.AuthPW = parseData.AuthPW;
                }

                if (parseData.TokenURL != null)
                {
                    existingApplication.TokenURL = parseData.TokenURL;
                }

                if (parseData.HeaderValues != null)
                {
                    existingApplication.HeaderValues = parseData.HeaderValues;
                }

                dbEntity.Entry(existingApplication).State = EntityState.Modified;
                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 23
0
        public void Update(int companyId, int subscriptionId, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                CompanyInSubscriptionPlan existingData = (from c in dbEntity.CompanyInSubscriptionPlan
                                                          where c.Id == subscriptionId && c.CompanyID == companyId
                                                          select c).SingleOrDefault <CompanyInSubscriptionPlan>();

                if (existingData == null)
                {
                    throw new CDSException(10302);
                }

                if (parseData.SubscriptionPlanId != null)
                {
                    existingData.SubscriptionPlanID = (int)parseData.SubscriptionPlanId;
                }

                if (parseData.SubscriptionName != null)
                {
                    existingData.SubscriptionName = parseData.SubscriptionName;
                }

                if (parseData.RatePer1KMessageIngestion.HasValue)
                {
                    existingData.RatePer1KMessageIngestion = (double)parseData.RatePer1KMessageIngestion;
                }

                if (parseData.RatePer1KMessageHotStore.HasValue)
                {
                    existingData.RatePer1KMessageHotStore = (double)parseData.RatePer1KMessageHotStore;
                }

                if (parseData.RatePer1KMessageHotStore.HasValue)
                {
                    existingData.RatePer1KMessageColdStore = (double)parseData.RatePer1KMessageColdStore;
                }

                if (parseData.StartDate.HasValue)
                {
                    existingData.StartDate = (DateTime)parseData.StartDate;
                }
                if (parseData.ExpiredDate.HasValue)
                {
                    existingData.ExpiredDate = (DateTime)parseData.ExpiredDate;
                }


                if (parseData.MaxMessageQuotaPerDay.HasValue)
                {
                    existingData.MaxMessageQuotaPerDay = (int)parseData.MaxMessageQuotaPerDay;
                }

                if (parseData.StoreHotMessage.HasValue)
                {
                    parseData.StoreHotMessage = (bool)parseData.StoreHotMessage;
                }

                if (parseData.StoreColdMessage.HasValue)
                {
                    existingData.StoreColdMessage = (bool)parseData.StoreColdMessage;
                }

                if (parseData.CosmosDBConnectionString != null)
                {
                    existingData.CosmosDBConnectionString = parseData.CosmosDBConnectionString;
                }

                if (parseData.CosmosDBName != null)
                {
                    existingData.CosmosDBName = parseData.CosmosDBName;
                }

                if (parseData.CosmosDBColletionId != null)
                {
                    existingData.CosmosDBCollectionID = parseData.CosmosDBColletionId;
                }

                if (parseData.CosmosDBCollectionTTL.HasValue)
                {
                    existingData.CosmosDBCollectionTTL = (int)parseData.CosmosDBCollectionTTL;
                }

                if (parseData.CosmosDBCollectionReservedUnits.HasValue)
                {
                    existingData.CosmosDBCollectionReservedUnits = (int)parseData.CosmosDBCollectionReservedUnits;
                }

                if (parseData.IoTHubConnectionString != null)
                {
                    existingData.IoTHubConnectionString = parseData.IoTHubConnectionString ?? "";
                }

                if (parseData.IoTHubConsumerGroup != null)
                {
                    existingData.IoTHubConsumerGroup = parseData.IoTHubConsumerGroup ?? "";
                }

                if (parseData.StorageConnectionString != null)
                {
                    existingData.StorageConnectionString = existingData.StorageConnectionString ?? "";
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 24
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                using (var dbEntityTransaction = dbEntity.Database.BeginTransaction())
                {
                    var existingData = dbEntity.Equipment.Find(id);
                    if (existingData == null)
                    {
                        throw new CDSException(10501);
                    }

                    if (parseData.Name != null)
                    {
                        existingData.Name = parseData.Name;
                    }

                    if (parseData.EquipmentId != null)
                    {
                        existingData.EquipmentId = parseData.EquipmentId;
                    }

                    if (parseData.EquipmentClassId.HasValue)
                    {
                        existingData.EquipmentClassId = Convert.ToInt32(parseData.EquipmentClassId);
                    }

                    if (parseData.FactoryId.HasValue)
                    {
                        existingData.FactoryId = Convert.ToInt32(parseData.FactoryId);
                    }

                    if (parseData.IoTDeviceId.HasValue)
                    {
                        existingData.IoTDeviceID = Convert.ToInt32(parseData.IoTDeviceId);
                    }

                    if (parseData.Latitude.HasValue)
                    {
                        existingData.Latitude = Convert.ToDouble(parseData.Latitude);
                    }

                    if (parseData.Longitude.HasValue)
                    {
                        existingData.Longitude = Convert.ToDouble(parseData.Longitude);
                    }

                    if (parseData.MaxIdleInSec.HasValue)
                    {
                        existingData.MaxIdleInSec = Convert.ToInt32(parseData.MaxIdleInSec);
                    }

                    dbEntity.SaveChanges();

                    /***** MetaData *****/
                    if (parseData.MetaData != null && parseData.MetaData.Count > 0)
                    {
                        string query_deleteExistingMetaDataValue = String.Format(@"
                            Delete From {0}.[MetaDataValue] 
                            Where
                                [ReferenceId] = @ReferenceId And 
                                [MetaDataDefinationId] 
                                    In (
                                        Select Id From {0}.[MetaDataDefination] 
                                        Where 
                                            CompanyId = @CompanyId 
                                            And EntityType = @EntityType
                                    )", Global.DBSchemaName);
                        List <SqlParameter> deleteParameters     = new List <SqlParameter>();
                        deleteParameters.Add(new SqlParameter("@ReferenceId", id));
                        deleteParameters.Add(new SqlParameter("@CompanyId", existingData.CompanyID));
                        deleteParameters.Add(new SqlParameter("@EntityType", Global.MetaDataEntityType.Equipment));
                        dbEntity.Database.ExecuteSqlCommand(query_deleteExistingMetaDataValue, deleteParameters.ToArray());

                        List <MetaDataValue> metaDataValueList = new List <MetaDataValue>();
                        foreach (var data in parseData.MetaData)
                        {
                            metaDataValueList.Add(new MetaDataValue()
                            {
                                MetaDataDefinationId = data.DefinationId,
                                ObjectValue          = data.ObjectValue ?? "",
                                ReferenceId          = id
                            });
                        }
                        dbEntity.MetaDataValue.AddRange(metaDataValueList);
                        dbEntity.SaveChanges();
                    }
                    dbEntityTransaction.Commit();
                }
            }
        }
Exemplo n.º 25
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                IoTDevice existingData = dbEntity.IoTDevice.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(10902);
                }

                if (parseData.IoTHubID.HasValue)
                {
                    existingData.IoTHubID = (int)parseData.IoTHubID;
                }

                if (parseData.IoTHubProtocol != null)
                {
                    existingData.IoTHubProtocol = parseData.IoTHubProtocol;
                }

                if (parseData.FactoryId.HasValue)
                {
                    existingData.FactoryID = (int)parseData.FactoryId;
                }

                if (parseData.DeviceTypeId.HasValue)
                {
                    existingData.DeviceTypeId = (int)parseData.DeviceTypeId;
                }

                if (parseData.DeviceVendor != null)
                {
                    existingData.DeviceVendor = parseData.DeviceVendor;
                }

                if (parseData.DeviceModel != null)
                {
                    existingData.DeviceModel = parseData.DeviceModel;
                }

                if (parseData.AuthenticationType != null)
                {
                    existingData.AuthenticationType = parseData.AuthenticationType;
                }

                if (parseData.MessageConvertScript != null)
                {
                    existingData.MessageConvertScript = parseData.MessageConvertScript;
                }

                if (parseData.EnableMessageConvert.HasValue)
                {
                    existingData.EnableMessageConvert = (bool)parseData.EnableMessageConvert;
                }

                if (parseData.DeviceCertificateID.HasValue)
                {
                    existingData.DeviceCertificateID = (int)parseData.DeviceCertificateID;
                }

                if (parseData.OriginMessage != null)
                {
                    existingData.OriginMessage = parseData.OriginMessage;
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 26
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = dbEntity.SubscriptionPlan.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(10701);
                }

                if (parseData.Name != null)
                {
                    existingData.Name = parseData.Name;
                }

                if (parseData.Description != null)
                {
                    existingData.Description = parseData.Description;
                }

                if (parseData.DefaultRatePer1KMessageIngestion.HasValue)
                {
                    existingData.DefaultRatePer1KMessageIngestion = parseData.DefaultRatePer1KMessageIngestion;
                }

                if (parseData.DefaultRatePer1KMessageHotStore.HasValue)
                {
                    existingData.DefaultRatePer1KMessageHotStore = parseData.DefaultRatePer1KMessageHotStore;
                }

                if (parseData.DefaultRatePer1KMessageHotStore.HasValue)
                {
                    existingData.DefaultRatePer1KMessageColdStore = parseData.DefaultRatePer1KMessageColdStore;
                }

                if (parseData.DefaultPlanDays.HasValue)
                {
                    existingData.DefaultPlanDays = (int)parseData.DefaultPlanDays;
                }

                if (parseData.DefaultMaxMessageQuotaPerDay.HasValue)
                {
                    existingData.DefaultMaxMessageQuotaPerDay = (int)parseData.DefaultMaxMessageQuotaPerDay;
                }

                if (parseData.DefaultStoreHotMessage.HasValue)
                {
                    existingData.DefaultStoreHotMessage = parseData.DefaultStoreHotMessage;
                }

                if (parseData.DefaultStoreColdMessage.HasValue)
                {
                    existingData.DefaultStoreColdMessage = parseData.DefaultStoreColdMessage;
                }

                if (parseData.DefaultCosmosDBConnectionString != null)
                {
                    existingData.DefaultCosmosDBConnectionString = parseData.DefaultCosmosDBConnectionString;
                }

                if (parseData.DefaultCollectionTTL.HasValue)
                {
                    existingData.DefaultCollectionTTL = parseData.DefaultCollectionTTL;
                }

                if (parseData.DefaultCollectionReservedUnits.HasValue)
                {
                    existingData.DefaultCollectionReservedUnits = parseData.DefaultCollectionReservedUnits;
                }

                if (parseData.DefaultIoTHubConnectionString != null)
                {
                    existingData.DefaultIoTHubConnectionString = parseData.DefaultIoTHubConnectionString ?? "";
                }

                if (parseData.DefaultStorageConnectionString != null)
                {
                    existingData.DefaultStorageConnectionString = parseData.DefaultStorageConnectionString ?? "";
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 27
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                IoTHub existingData = dbEntity.IoTHub.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(10901);
                }

                if (parseData.IoTHubName != null)
                {
                    existingData.IoTHubName = parseData.IoTHubName;
                }

                if (parseData.Description != null)
                {
                    existingData.Description = parseData.Description;
                }

                if (parseData.IoTHubEndPoint != null)
                {
                    existingData.IoTHubEndPoint = parseData.IoTHubEndPoint;
                }

                if (parseData.IoTHubConnectionString != null)
                {
                    existingData.IoTHubConnectionString = parseData.IoTHubConnectionString;
                }

                if (parseData.EventConsumerGroup != null)
                {
                    existingData.EventConsumerGroup = parseData.EventConsumerGroup;
                }

                if (parseData.EventHubStorageConnectionString != null)
                {
                    existingData.EventHubStorageConnectionString = parseData.EventHubStorageConnectionString;
                }

                if (parseData.UploadContainer != null)
                {
                    existingData.UploadContainer = parseData.UploadContainer;
                }

                if (parseData.EnableMultipleReceiver.HasValue)
                {
                    existingData.EnableMultipleReceiver = (bool)parseData.EnableMultipleReceiver;
                }

                try
                {
                    dbEntity.SaveChanges();
                }
                catch (DbUpdateException ex)
                {
                    if (ex.InnerException.InnerException.Message.Contains("Cannot insert duplicate key"))
                    {
                        throw new CDSException(10905);
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
        }
Exemplo n.º 28
0
        public void Update(int id, Format_Update parseData)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingData = dbEntity.WidgetCatalog.Find(id);
                if (existingData == null)
                {
                    throw new CDSException(12302);
                }

                if (parseData.Content != null)
                {
                    try
                    {
                        JObject.Parse(parseData.Content);
                    }
                    catch
                    {
                        throw new CDSException(12303);
                    }
                    existingData.Content = parseData.Content;
                }

                if (parseData.Name != null)
                {
                    existingData.Name = parseData.Name;
                }

                if (parseData.MessageCatalogId.HasValue)
                {
                    existingData.MessageCatalogID = parseData.MessageCatalogId;
                }

                if (parseData.Level != null)
                {
                    existingData.Level = parseData.Level;
                }

                if (parseData.WidgetClassKey.HasValue)
                {
                    existingData.WidgetClassKey = (int)parseData.WidgetClassKey;
                }

                if (parseData.Title != null)
                {
                    existingData.Title = parseData.Title;
                }

                if (parseData.TitleBgColor != null)
                {
                    existingData.TitleBgColor = parseData.TitleBgColor;
                }

                if (parseData.ContentBgColor != null)
                {
                    existingData.ContentBgColor = parseData.ContentBgColor;
                }

                dbEntity.SaveChanges();
            }
        }
Exemplo n.º 29
0
        public void UpdateById(int id, Format_Update dataModel)
        {
            using (CDStudioEntities dbEntity = new CDStudioEntities())
            {
                var existingCompany = dbEntity.Company.Find(id);
                if (existingCompany == null || existingCompany.DeletedFlag == true)
                {
                    throw new CDSException(10701);
                }

                if (dataModel.Name != null)
                {
                    existingCompany.Name = dataModel.Name;
                }

                if (dataModel.ShortName != null)
                {
                    existingCompany.ShortName = dataModel.ShortName;
                }

                if (dataModel.Address != null)
                {
                    existingCompany.Address = dataModel.Address;
                }

                if (dataModel.CompanyWebSite != null)
                {
                    existingCompany.CompanyWebSite = dataModel.CompanyWebSite;
                }

                if (dataModel.ContactName != null)
                {
                    existingCompany.ContactName = dataModel.ContactName;
                }

                if (dataModel.ContactEmail != null)
                {
                    existingCompany.ContactEmail = dataModel.ContactEmail;
                }

                if (dataModel.ContactPhone != null)
                {
                    existingCompany.ContactPhone = dataModel.ContactPhone;
                }

                if (dataModel.Latitude != 0)
                {
                    existingCompany.Latitude = dataModel.Latitude;
                }

                if (dataModel.Longitude != 0)
                {
                    existingCompany.Longitude = dataModel.Longitude;
                }

                if (dataModel.CultureInfoId != null)
                {
                    existingCompany.CultureInfo = dataModel.CultureInfoId;
                }

                if (dataModel.AllowDomain != null)
                {
                    existingCompany.AllowDomain = dataModel.AllowDomain;
                }

                if (dataModel.ExtAppAuthenticationKey != null)
                {
                    existingCompany.ExtAppAuthenticationKey = dataModel.ExtAppAuthenticationKey;
                }

                if (dataModel.DeletedFlag.HasValue)
                {
                    existingCompany.DeletedFlag = (bool)dataModel.DeletedFlag;
                }

                existingCompany.UpdatedAt = DateTime.UtcNow;
                dbEntity.SaveChanges();
            }
        }