Beispiel #1
0
        public string DeleteCDFs(string uList)
        {
            string result = string.Empty;

            using (var sdaCloudEntities = new SDACloudEntities())
            {
                List <string> tagIds = uList.Split(',').ToList();
                var           clientDefinedFields = new List <ClientDefinedField>();
                foreach (var uv in tagIds)
                {
                    int uvId;
                    Int32.TryParse(uv, out uvId);
                    var clientDefinedField = sdaCloudEntities.ClientDefinedFields.Where(q => q.ClientDefinedFieldID == uvId).SingleOrDefault();
                    if (clientDefinedField != null)
                    {
                        clientDefinedFields.Add(clientDefinedField);
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(result))
                        {
                            result += ",";
                        }
                        result += uv;
                    }
                }
                foreach (var cdf in clientDefinedFields)
                {
                    Mapper.CreateMap <ClientDefinedField, ClientDefinedFieldDto>();

                    var existingCDF = Mapper.Map <ClientDefinedField, ClientDefinedFieldDto>(cdf);
                    ////Mapper.AssertConfigurationIsValid();

                    InterfaceXRefDL interfaceXrefDL = new InterfaceXRefDL();
                    var             deleted         = interfaceXrefDL.DeleteInterfaceXRef(existingCDF);
                    if (deleted >= 0)
                    {
                        //check this
                        //sdaCloudEntities.DeleteObject(cdf);
                    }
                }
                sdaCloudEntities.SaveChanges();
            }
            return(result);
        }
Beispiel #2
0
        public int UpdateCDFField(int cdfId, string field, string newValue)
        {
            int result = 0;

            using (var sdaCloudEntities = new SDACloudEntities())
            {
                using (sdaCloudEntities)
                {
                    using (var transactionScope = new TransactionScope())
                    {
                        var existingCDF = sdaCloudEntities.ClientDefinedFields.FirstOrDefault(i => i.ClientDefinedFieldID == cdfId);

                        if (existingCDF != null)
                        {
                            Type         t    = existingCDF.GetType();
                            PropertyInfo info = t.GetProperty(field);

                            if (info == null)
                            {
                                return(-1);
                            }
                            if (!info.CanWrite)
                            {
                                return(-1);
                            }
                            info.SetValue(existingCDF, newValue, null);

                            result = sdaCloudEntities.SaveChanges();

                            Mapper.CreateMap <ClientDefinedField, ClientDefinedFieldDto>();

                            var cDF = Mapper.Map <ClientDefinedField, ClientDefinedFieldDto>(existingCDF);
                            ////Mapper.AssertConfigurationIsValid();

                            InterfaceXRefDL interfaceXrefDL = new InterfaceXRefDL();
                            var             interfaceXrefId = interfaceXrefDL.UpdateInterfaceXRef(cDF);
                        }

                        transactionScope.Complete();
                    }
                }
            }
            return(result);
        }
Beispiel #3
0
        public int AddClientDefinedField(ClientDefinedFieldDto clientDefinedField)
        {
            int result;

            using (var sdaCloudEntities = new SDACloudEntities())
            {
                using (var transactionScope = new TransactionScope())
                {
                    var existingCDF = new ClientDefinedField
                    {
                        ClientID     = clientDefinedField.ClientID,
                        Table        = clientDefinedField.Table,
                        Field        = clientDefinedField.Field,
                        ColumnHeader = clientDefinedField.ColumnHeader,
                        Format       = clientDefinedField.Format,
                        SDARangeName = clientDefinedField.SDARangeName
                    };

                    sdaCloudEntities.ClientDefinedFields.AddObject(existingCDF);

                    result = sdaCloudEntities.SaveChanges();

                    if (result > 0)
                    {
                        InterfaceXRefDL interfaceXrefDL = new InterfaceXRefDL();
                        var             interfaceXrefId = interfaceXrefDL.AddInterfaceXRef(clientDefinedField);
                        if (interfaceXrefId > 0)
                        {
                            existingCDF.InterfaceXRefID = interfaceXrefId;
                            sdaCloudEntities.SaveChanges();
                        }
                    }

                    result = existingCDF.ClientDefinedFieldID;

                    transactionScope.Complete();
                }
            }
            return(result);
        }