public PropertyValueModel Get(int id)
        {
            var entity = _propertyValueService.GetPropertyValueById(id);
            var model  = new PropertyValueModel
            {
                Id = entity.Id,

//		        Property = entity.Property,

                Value = entity.Value,

                Adduser = new UserModel {
                    Id = entity.Adduser.Id, UserName = entity.Adduser.UserName
                },

                Addtime = entity.Addtime,

                UpdUser = new UserModel {
                    Id = entity.UpdUser.Id, UserName = entity.UpdUser.UserName
                },

                UpdTime = entity.UpdTime,
            };

            return(model);
        }
        public async Task <IActionResult> estimateValue(List <PostDataModel> property)
        {
            string BaseUrl     = _configuration.GetSection("ApiURL:baseURL").Value;
            string postUserURL = _configuration.GetSection("ApiURL:valuationURL").Value;;

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri(BaseUrl);
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            var content = new StringContent(JsonConvert.SerializeObject(property), Encoding.UTF8, "application/json");
            HttpResponseMessage response = await client.PostAsync(postUserURL, content);

            PropertyValueModel value = new PropertyValueModel();

            if (response.IsSuccessStatusCode)
            {
                string jsonString = await response.Content.ReadAsStringAsync();

                value = JsonConvert.DeserializeObject <PropertyValueModel>(jsonString);
            }
            return(Json(value, new JsonSerializerSettings
            {
                Formatting = Formatting.Indented,
            }));
        }
Example #3
0
        public async Task <HttpResponseMessage> estimateValue(List <PostDataModel> property)
        {
            HttpRequestMessage request = Request;
            PropertyValueModel value   = new PropertyValueModel();
            int returnValue            = await postDataRepository.estimateProperty(property);

            value.Value = returnValue;
            return(GlobalFunctions.CreateResponse <PropertyValueModel>(request, HttpStatusCode.OK, value));
        }
Example #4
0
        /// <summary>
        /// Creates the property value model.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>PropertyValueModel.</returns>
        /// <exception cref="System.ArgumentNullException">value</exception>
        public static PropertyValueModel CreatePropertyValueModel(PropertyValueBase value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var model = new PropertyValueModel();
            model.InjectFrom<CloneInjection>(value);
            return model;
        }
Example #5
0
        public static PropertyValueModel DataReader_to_PropertyValueModel(SqlDataReader reader)
        {
            PropertyValueModel propertyValue = new PropertyValueModel();

            propertyValue.PropertyID = (Guid)reader["PropertyID"];

            propertyValue.PropertyValueID      = (Guid)reader["PropertyValueID"];
            propertyValue.PropertyValueName    = (String)reader["PropertyValueName"];
            propertyValue.PropertyValueNameKey = (String)reader["PropertyValueNameKey"];
            propertyValue.OrderID     = (int)reader["OrderID"];
            propertyValue.Visible     = (bool)reader["Visible"];
            propertyValue.CreatedDate = (DateTime)reader["CreatedDate"];

            return(propertyValue);
        }
        public bool Post(PropertyValueModel model)
        {
            var entity = new PropertyValueEntity
            {
//				Property = model.Property,

                Value = model.Value,

                Adduser = (UserBase)_workContext.CurrentUser,

                Addtime = DateTime.Now,

                UpdUser = (UserBase)_workContext.CurrentUser,

                UpdTime = DateTime.Now,
            };

            if (_propertyValueService.Create(entity).Id > 0)
            {
                return(true);
            }
            return(false);
        }
        public bool Put(PropertyValueModel model)
        {
            var entity = _propertyValueService.GetPropertyValueById(model.Id);

            if (entity == null)
            {
                return(false);
            }

//			entity.Property = model.Property;

            entity.Value = model.Value;

            entity.UpdUser = (UserBase)_workContext.CurrentUser;

            entity.UpdTime = DateTime.Now;

            if (_propertyValueService.Update(entity) != null)
            {
                return(true);
            }
            return(false);
        }
Example #8
0
        /// <summary>
        /// Creates the property value model.
        /// </summary>
        /// <param name="value">The value.</param>
        /// <returns>PropertyValueModel.</returns>
        /// <exception cref="System.ArgumentNullException">value</exception>
        public static PropertyValueModel CreatePropertyValueModel(PropertyValueBase value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            var model = new PropertyValueModel();
            model.InjectFrom<CloneInjection>(value);
            return model;
        }
Example #9
0
        public static DataAccessResponseType InsertPropertyValue(string sqlPartition, string schemaId, PropertyValueModel propertyValue)
        {
            DataAccessResponseType response = new DataAccessResponseType();

            StringBuilder SqlStatement = new StringBuilder();


            //newAccountModel.Provisioned = false;

            //SQL Statement =============================================================
            SqlStatement.Append("INSERT INTO  ");
            SqlStatement.Append(schemaId);
            SqlStatement.Append(".PropertyValue (");

            SqlStatement.Append("PropertyID,");
            SqlStatement.Append("PropertyValueID,");
            SqlStatement.Append("PropertyValueName,");
            SqlStatement.Append("PropertyValueNameKey,");
            SqlStatement.Append("CreatedDate, ");
            SqlStatement.Append("Visible");

            SqlStatement.Append(") VALUES (");

            //Using parameterized queries to protect against injection
            SqlStatement.Append("@PropertyID, ");
            SqlStatement.Append("@PropertyValueID, ");
            SqlStatement.Append("@PropertyValueName, ");
            SqlStatement.Append("@PropertyValueNameKey, ");
            SqlStatement.Append("@CreatedDate, ");
            SqlStatement.Append("@Visible");

            SqlStatement.Append(")");

            //SqlCommand sqlCommand = new SqlCommand(SqlStatement.ToString(), Sahara.Core.Settings.Azure.Databases.DatabaseConnections.DatabasePartitionSqlConnection(sqlPartition));
            SqlCommand sqlCommand = Sahara.Core.Settings.Azure.Databases.DatabaseConnections.DatabasePartitionSqlConnection(sqlPartition).CreateCommand();

            sqlCommand.CommandText = SqlStatement.ToString();



            //Using parameterized queries to protect against injection
            sqlCommand.Parameters.Add("@PropertyID", SqlDbType.UniqueIdentifier);
            sqlCommand.Parameters.Add("@PropertyValueID", SqlDbType.UniqueIdentifier);
            sqlCommand.Parameters.Add("@PropertyValueName", SqlDbType.Text);
            sqlCommand.Parameters.Add("@PropertyValueNameKey", SqlDbType.Text);
            sqlCommand.Parameters.Add("@CreatedDate", SqlDbType.DateTime);
            sqlCommand.Parameters.Add("@Visible", SqlDbType.Bit);

            //Assign values
            sqlCommand.Parameters["@PropertyID"].Value           = propertyValue.PropertyID;
            sqlCommand.Parameters["@PropertyValueID"].Value      = propertyValue.PropertyValueID;
            sqlCommand.Parameters["@PropertyValueName"].Value    = propertyValue.PropertyValueName;
            sqlCommand.Parameters["@PropertyValueNameKey"].Value = propertyValue.PropertyValueNameKey;
            sqlCommand.Parameters["@CreatedDate"].Value          = DateTime.UtcNow;
            sqlCommand.Parameters["@Visible"].Value = propertyValue.Visible;

            int insertAccountResult = 0;

            sqlCommand.Connection.OpenWithRetry();

            try
            {
                insertAccountResult = sqlCommand.ExecuteNonQueryWithRetry(); // returns Int indicating number of rows affected
                if (insertAccountResult > 0)
                {
                    response.isSuccess = true;
                }
            }
            catch (Exception e)
            {
                //Log exception and email platform admins
                PlatformExceptionsHelper.LogExceptionAndAlertAdmins(
                    e,
                    "attempting to insert a property value into SQL",
                    System.Reflection.MethodBase.GetCurrentMethod()
                    );

                response.isSuccess    = false;
                response.ErrorMessage = e.Message;
                return(response);
            }

            sqlCommand.Connection.Close();

            return(response);
        }
Example #10
0
        /// <summary>
        /// 获取商品拥有的属性集合 如颜色 有几种颜色,尺寸有几种尺寸
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        private List <PropertyModel> GetHaveProperty(int productId)
        {
            try
            {
                var                      skuList      = bllMall.GetProductSkuList(productId);
                List <string>            propIdList   = new List <string>();//获取商品拥有的所有属性ID集合
                Dictionary <int, string> propKeyValue = new Dictionary <int, string>();
                foreach (var sku in skuList)
                {
                    if (!string.IsNullOrEmpty(sku.PropValueIdEx1) && !string.IsNullOrEmpty(sku.PropValueIdEx2))
                    {
                        sku.Props = bllMall.GetProductProperties(sku.SkuId);//兼容efast同步 无用
                    }

                    foreach (var item in sku.Props.Split(';'))
                    {
                        string propId = item.Split(':')[0];
                        if (!propIdList.Contains(propId))
                        {
                            propIdList.Add(propId);
                            string propName = item.Split(':')[2];
                            propKeyValue.Add(int.Parse(propId), propName);
                        }
                    }
                }


                List <PropertyModel> data = new List <PropertyModel>();
                foreach (var propId in propIdList)
                {
                    PropertyModel model = new PropertyModel();
                    Property      prop  = new Property();
                    prop.property_id          = int.Parse(propId);
                    prop.property_name        = propKeyValue[int.Parse(propId)].Trim();
                    model.property            = prop;
                    model.property_value_list = new List <PropertyValueModel>();
                    foreach (var sku in skuList)
                    {
                        foreach (var item in sku.Props.Split(';'))
                        {
                            string propIdNew     = item.Split(':')[0];
                            string propValue     = item.Split(':')[1];
                            string propValueName = item.Split(':')[3];
                            if (propId == propIdNew)
                            {
                                PropertyValueModel valueModel = new PropertyValueModel();
                                valueModel.property_value_id   = int.Parse(propValue);
                                valueModel.property_value_name = propValueName.Trim();
                                if (model.property_value_list.Where(p => p.property_value_id == valueModel.property_value_id).Count() == 0)
                                {
                                    model.property_value_list.Add(valueModel);
                                }
                            }
                        }
                    }

                    data.Add(model);
                }


                return(data);
            }
            catch (Exception)
            {
                return(new List <PropertyModel>());
            }
        }
Example #11
0
        public static DataAccessResponseType CreatePropertyValue(Account account, PropertyModel property, string propertyValueName)
        {
            //TO DO: Always clear/update caches AND update counts!


            #region Verify value

            if (propertyValueName == null || propertyValueName == "")
            {
                return(new DataAccessResponseType
                {
                    isSuccess = false,
                    ErrorMessage = "Value must have a value!"
                });
            }

            if (propertyValueName.Length > 60)
            {
                return(new DataAccessResponseType
                {
                    isSuccess = false,
                    ErrorMessage = "Values cannot be longer than 60 characters!"
                });
            }

            #endregion



            var response = new DataAccessResponseType();

            #region Validate Property Value Name (Depricate ???)

            /*
             * ValidationResponseType ojectNameValidationResponse = ValidationManager.IsValidObjectName(propertyValueName);
             * if (!ojectNameValidationResponse.isValid)
             * {
             *  response.isSuccess = false;
             *  response.ErrorMessage = ojectNameValidationResponse.validationMessage;
             *  response.ErrorMessages.Add(ojectNameValidationResponse.validationMessage);
             *
             *  return response;
             * }
             */
            #endregion

            #region Validate Property can have values

            if (property.PropertyTypeNameKey != "predefined")
            {
                return(new DataAccessResponseType
                {
                    isSuccess = false,
                    ErrorMessage = "This property cannot be assigned predefined values"
                });
            }

            #endregion

            #region Verify value does not already exist on this property

            foreach (PropertyValueModel propertyValueModel in property.Values)
            {
                if (propertyValueModel.PropertyValueNameKey == Common.Methods.ObjectNames.ConvertToObjectNameKey(propertyValueName))
                {
                    return(new DataAccessResponseType
                    {
                        isSuccess = false,
                        ErrorMessage = "This property already has this value assigned."
                    });
                }
            }

            #endregion

            var propertyValue = new PropertyValueModel
            {
                PropertyID           = property.PropertyID,
                PropertyValueID      = Guid.NewGuid(),
                PropertyValueName    = propertyValueName,
                PropertyValueNameKey = Sahara.Core.Common.Methods.ObjectNames.ConvertToObjectNameKey(propertyValueName),
                Visible = true
            };

            response = Sql.Statements.InsertStatements.InsertPropertyValue(account.SqlPartition, account.SchemaName, propertyValue);

            if (response.isSuccess)
            {
                //Clear Caches:
                Caching.InvalidateAllPropertyCachesForAccount(account.AccountNameKey);
            }

            response.SuccessMessage = propertyValue.PropertyValueID.ToString(); //<--Returned for logging purposes

            return(response);
        }
Example #12
0
        public static DataAccessResponseType DeletePropertyValue(Account account, PropertyModel property, PropertyValueModel propertyValue)
        {
            var response = new DataAccessResponseType();

            #region Check if property value is currently in use on ANY documents for this account

            #region Get any relevant documents (Legacy)

            /*
             * //Get the DocumentDB Client
             * var client = Sahara.Core.Settings.Azure.DocumentDB.DocumentClients.AccountDocumentClient;
             * //var dbSelfLink = Sahara.Core.Settings.Azure.DocumentDB.AccountPartitionDatabaseSelfLink;
             * client.OpenAsync();
             *
             * string sqlQuery = "SELECT Top 1 * FROM Products p WHERE p.Properties." + property.PropertyName + " = '" + propertyValue.PropertyValueName + "'";
             *
             * //Build a collection Uri out of the known IDs
             * //(These helpers allow you to properly generate the following URI format for Document DB:
             * //"dbs/{xxx}/colls/{xxx}/docs/{xxx}"
             * Uri collectionUri = UriFactory.CreateDocumentCollectionUri(Sahara.Core.Settings.Azure.DocumentDB.AccountPartitionDatabaseId, account.DocumentPartition);
             * //Uri storedProcUri = UriFactory.CreateStoredProcedureUri(Sahara.Core.Settings.Azure.DocumentDB.AccountPartitionDatabaseId, account.DocumentPartition, "UpdateProduct");
             *
             * var document = client.CreateDocumentQuery<Document>(collectionUri.ToString(), sqlQuery).AsEnumerable().FirstOrDefault();
             */
            #endregion

            #endregion

            #region Get any relevant documents (from Search)

            //$filter=tags/any(t: t eq '345')
            string searchFilter = property.SearchFieldName + "/any(s: s eq '" + propertyValue.PropertyValueName + "')";

            var documentSearchResult = ProductSearchManager.SearchProducts(account.SearchPartition, account.ProductSearchIndex, "", searchFilter, "relevance", 0, 1);

            #endregion

            if (documentSearchResult.Count > 0)
            {
                return(new DataAccessResponseType
                {
                    isSuccess = false,
                    ErrorMessage = "Cannot delete a property value that is in use on a product. Please remove all associations before deleting."
                });
            }
            else
            {
                response.isSuccess = Sql.Statements.DeleteStatements.DeletePropertyValue(account.SqlPartition, account.SchemaName, propertyValue.PropertyValueID.ToString());
            }

            if (response.isSuccess)
            {
                //Clear Category Caches:
                Caching.InvalidateAllPropertyCachesForAccount(account.AccountNameKey);
            }

            return(response);
        }