public int SaveAttribute(eshopBE.Attribute attribute) { AttributeDL attributeDL = new AttributeDL(); if (attribute.AttributeID > 0) return attributeDL.UpdateAttribute(attribute); else return attributeDL.SaveAttribute(attribute); }
public int UpdateAttribute(eshopBE.Attribute attribute) { int status = 0; using (SqlConnection objConn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString)) { using (SqlCommand objComm = new SqlCommand("UPDATE attribute SET name=@name, isDescription=@isDescription WHERE attributeID=@attributeID", objConn)) { try { objConn.Open(); objComm.Parameters.Add("@name", SqlDbType.NVarChar, 100).Value = attribute.Name; objComm.Parameters.Add("@isDescription", SqlDbType.Bit).Value = attribute.IsDescription; objComm.Parameters.Add("@attributeID", SqlDbType.Int).Value = attribute.AttributeID; status = objComm.ExecuteNonQuery(); //if (status > 0) //SaveAttributeValues(attribute.Values); } catch (SqlException ex) { ErrorLog.LogError(ex); throw new DLException("Error while updating attribute.", ex); } } } return status; }
/*private eshopBE.Attribute GetAttribute(int attributeID, string name) { eshopBE.Attribute attribute = null; using (SqlConnection objConn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString)) using (SqlCommand objComm = new SqlCommand("SELECT attributeID, name FROM attribute", objConn)) { objConn.Open(); if(attributeID>0) { objComm.CommandText += " WHERE attributeID=@attributeID"; objComm.Parameters.Add("@attributeID", SqlDbType.Int).Value = attributeID; } else if (name != string.Empty) { objComm.CommandText += " WHERE name=@name"; objComm.Parameters.Add("@name", SqlDbType.NVarChar, 50).Value = name; } using (SqlDataReader reader = objComm.ExecuteReader()) while (reader.Read()) { attribute = new eshopBE.Attribute(); attribute.AttributeID = reader.GetInt32(0); attribute. } }*/ public int SaveAttribute(eshopBE.Attribute attribute) { int attributeID = 0; using (SqlConnection objConn = new SqlConnection(WebConfigurationManager.ConnectionStrings["eshopConnectionString"].ConnectionString)) { using (SqlCommand objComm = new SqlCommand("INSERT INTO attribute (name, isDescription) VALUES (@name, @isDescription);SELECT SCOPE_IDENTITY()", objConn)) { try { objConn.Open(); objComm.Parameters.Add("@name", SqlDbType.NVarChar, 100).Value = attribute.Name; objComm.Parameters.Add("@isDescription", SqlDbType.Bit).Value = attribute.IsDescription; attributeID = int.Parse(objComm.ExecuteScalar().ToString()); if (attributeID > 0) SaveAttributeValue(new AttributeValue(-1, "NP", attributeID, 0, string.Empty, 0), false); //SaveAttributeValues(attribute.Values); } catch (SqlException ex) { ErrorLog.LogError(ex); throw new DLException("Error while saving attribute.", ex); } } } return attributeID; }