private Int64 AddUpdateProductCustomer(ProductCustomrRate prodcust) { Int64 PCRId = 0; string insertProcedure = "[CreateProductCustomerRate]"; SqlCommand insertCommand = new SqlCommand(insertProcedure, connection); insertCommand.CommandType = CommandType.StoredProcedure; if (prodcust.PCRId != 0) { insertCommand.Parameters.AddWithValue("@PCRId", prodcust.PCRId); } else { insertCommand.Parameters.AddWithValue("@PCRId", 0); } if (prodcust.CustId != 0) { insertCommand.Parameters.AddWithValue("@CustId", prodcust.CustId); } else { insertCommand.Parameters.AddWithValue("@CustId", 0); } if (prodcust.ProductId != 0) { insertCommand.Parameters.AddWithValue("@ProductId", prodcust.ProductId); } else { insertCommand.Parameters.AddWithValue("@ProductId", 0); } if (prodcust.Serial != 0) { insertCommand.Parameters.AddWithValue("@Serial", prodcust.Serial); } else { insertCommand.Parameters.AddWithValue("@Serial", 0); } if (prodcust.UserId != 0) { insertCommand.Parameters.AddWithValue("@UserId", prodcust.UserId); } else { insertCommand.Parameters.AddWithValue("@UserId", 0); } if (prodcust.Price != 0) { insertCommand.Parameters.AddWithValue("@Price", prodcust.Price); } else { insertCommand.Parameters.AddWithValue("@Price", 0); } if (prodcust.ProdCatId != 0) { insertCommand.Parameters.AddWithValue("@ProdCatId", prodcust.ProdCatId); } else { insertCommand.Parameters.AddWithValue("@ProdCatId", 0); } if (prodcust.IsActive) { insertCommand.Parameters.AddWithValue("@IsActive", prodcust.IsActive); } else { insertCommand.Parameters.AddWithValue("@IsActive", 0); } if ((prodcust.EffectiveFrom) != null) { insertCommand.Parameters.AddWithValue("@EffectiveFrom", prodcust.EffectiveFrom); } else { insertCommand.Parameters.AddWithValue("@EffectiveFrom", DBNull.Value); } if ((prodcust.EffectiveUpto) != null) { insertCommand.Parameters.AddWithValue("@EffectiveUpto", prodcust.EffectiveUpto); } else { insertCommand.Parameters.AddWithValue("@EffectiveUpto", DBNull.Value); } if (prodcust.Type != 0) { insertCommand.Parameters.AddWithValue("@Type", prodcust.Type); } else { insertCommand.Parameters.AddWithValue("@Type", 0); } insertCommand.Parameters.Add("@PCRIdOut", System.Data.SqlDbType.Int); insertCommand.Parameters["@PCRIdOut"].Direction = ParameterDirection.Output; insertCommand.Parameters.Add("@ReturnValue", System.Data.SqlDbType.Int); insertCommand.Parameters["@ReturnValue"].Direction = ParameterDirection.Output; try { int count = 0; connection.Open(); insertCommand.ExecuteNonQuery(); if (insertCommand.Parameters["@ReturnValue"].Value != DBNull.Value) { count = System.Convert.ToInt32(insertCommand.Parameters["@ReturnValue"].Value); } if (count != 0) { if (insertCommand.Parameters["@PCRIdOut"].Value != DBNull.Value) { PCRId = System.Convert.ToInt32(insertCommand.Parameters["@PCRIdOut"].Value); } else { PCRId = prodcust.PCRId; } } return(PCRId); } catch (Exception ex) { log.logErrorMessage(""); log.logErrorMessage(ex.StackTrace); return(PCRId); } finally { connection.Close(); } }
public List <dynamic> AddUpdateProducts(List <CustomerInfo> custinfo, ProductMasterDTO productMasterDTO) { List <dynamic> objDynamic = new List <dynamic>(); CustomerInfo customerInfo = new CustomerInfo(); ProductCustomrRate productCustomrRate = new ProductCustomrRate(); productMasterDTO.UserId = Convert.ToInt64(UserID); Int64 ProductId = 0; if (!string.IsNullOrEmpty(productMasterDTO.strProductId)) { ProductId = Convert.ToInt64(securityHelper.Decrypt(productMasterDTO.strProductId, false)); productMasterDTO.ProductId = ProductId; productMasterDTO.Type = 2; } else { productMasterDTO.Type = 1; } ProductId = AddUpdateProduct(productMasterDTO); for (int i = 0; i < custinfo.Count; i++) { DateTime?dateSample; dateSample = null; customerInfo = custinfo[i]; if (checkData(customerInfo)) { if (!string.IsNullOrEmpty(customerInfo.PCRId.ToString())) { productCustomrRate.PCRId = Convert.ToInt64(customerInfo.PCRId); productCustomrRate.Type = 2; } else { productCustomrRate.PCRId = 0; productCustomrRate.Type = 1; } productCustomrRate.ProductId = ProductId; productCustomrRate.CustId = customerInfo.CustId; if (!string.IsNullOrEmpty(customerInfo.IsActive.ToString())) { productCustomrRate.IsActive = Convert.ToBoolean(customerInfo.IsActive); } if (!string.IsNullOrEmpty(customerInfo.Price.ToString())) { productCustomrRate.Price = Convert.ToDecimal(customerInfo.Price); } if (!string.IsNullOrEmpty(customerInfo.ProdCatId.ToString())) { productCustomrRate.ProdCatId = Convert.ToInt64(customerInfo.ProdCatId); } if (!string.IsNullOrEmpty(customerInfo.ExpDate.ToString())) { productCustomrRate.EffectiveUpto = Convert.ToDateTime(customerInfo.ExpDate); } else { productCustomrRate.EffectiveUpto = dateSample; } productCustomrRate.EffectiveFrom = dateSample; productCustomrRate.Serial = i + 1; productCustomrRate.UserId = Convert.ToInt64(UserID); Int64 pcr = AddUpdateProductCustomer(productCustomrRate); } } objDynamic.Add(securityHelper.Encrypt(ProductId.ToString(), false)); return(objDynamic); }