Beispiel #1
0
        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);
        }
Beispiel #2
0
        private Int64 AddUpdateProduct(ProductMasterDTO prodmstr)
        {
            Int64  PMId            = 0;
            string insertProcedure = "[CreateProductMaster]";

            SqlCommand insertCommand = new SqlCommand(insertProcedure, connection);

            insertCommand.CommandType = CommandType.StoredProcedure;


            if (prodmstr.ProductId != 0)
            {
                insertCommand.Parameters.AddWithValue("@ProductId", prodmstr.ProductId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ProductId", 0);
            }

            if (!string.IsNullOrEmpty(prodmstr.PartNo))
            {
                insertCommand.Parameters.AddWithValue("@PartNo", prodmstr.PartNo);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@PartNo", DBNull.Value);
            }
            if (prodmstr.UserId != 0)
            {
                insertCommand.Parameters.AddWithValue("@UserId", prodmstr.UserId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@UserId", 0);
            }
            if (!string.IsNullOrEmpty(prodmstr.Model))
            {
                insertCommand.Parameters.AddWithValue("@Model", prodmstr.Model);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@Model", DBNull.Value);
            }
            if (prodmstr.ManufacturerId != 0)
            {
                insertCommand.Parameters.AddWithValue("@ManufacturerId", prodmstr.ManufacturerId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ManufacturerId", 0);
            }
            if (prodmstr.ProductTypeId != 0)
            {
                insertCommand.Parameters.AddWithValue("@ProductTypeId", prodmstr.ProductTypeId);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ProductTypeId", 0);
            }
            if (prodmstr.IsActive)
            {
                insertCommand.Parameters.AddWithValue("@IsActive", prodmstr.IsActive);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@IsActive", 0);
            }
            if (prodmstr.Type != 0)
            {
                insertCommand.Parameters.AddWithValue("@Type", prodmstr.Type);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@Type", 0);
            }

            if (!string.IsNullOrEmpty(prodmstr.Spec))
            {
                insertCommand.Parameters.AddWithValue("@Spec", prodmstr.Spec);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@Spec", DBNull.Value);
            }
            if (!string.IsNullOrEmpty(prodmstr.ImageType))
            {
                insertCommand.Parameters.AddWithValue("@ImageType", prodmstr.ImageType);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ImageType", DBNull.Value);
            }

            if (!string.IsNullOrEmpty(prodmstr.ImageLength))
            {
                insertCommand.Parameters.AddWithValue("@ImageLength", prodmstr.ImageLength);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ImageLength", DBNull.Value);
            }
            if (!string.IsNullOrEmpty(prodmstr.ImageID))
            {
                insertCommand.Parameters.AddWithValue("@ImageID", prodmstr.ImageID);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ImageID", DBNull.Value);
            }

            if (!string.IsNullOrEmpty(prodmstr.ImagePath))
            {
                insertCommand.Parameters.AddWithValue("@ImagePath", prodmstr.ImagePath);
            }
            else
            {
                insertCommand.Parameters.AddWithValue("@ImagePath", DBNull.Value);
            }

            insertCommand.Parameters.Add("@ProductIdOut", System.Data.SqlDbType.Int);
            insertCommand.Parameters["@ProductIdOut"].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["@ProductIdOut"].Value != DBNull.Value)
                    {
                        PMId = System.Convert.ToInt32(insertCommand.Parameters["@ProductIdOut"].Value);
                    }
                    else
                    {
                        PMId = prodmstr.ProductId;
                    }
                }


                return(PMId);
            }
            catch (Exception ex)
            {
                log.logErrorMessage("");
                log.logErrorMessage(ex.StackTrace);
                return(PMId);
            }
            finally
            {
                connection.Close();
            }
        }
        public JsonResult SaveFiles(string[] description, HttpPostedFileBase files, AddProductDTO addProductDTO)
        {
            #region comment
            string           Message, fileName, actualFileName;
            string           Manufacturer = string.Empty, Model = string.Empty, PartNo = string.Empty, ProductType = string.Empty, Spec = string.Empty, ProductID = string.Empty;
            ProductMasterDTO productMasterDTO = new ProductMasterDTO();
            Message = fileName = actualFileName = string.Empty;
            bool   flag    = false;
            string strpath = System.Configuration.ConfigurationManager.AppSettings["UploadImagePath"];
            int    size    = 0;
            if (Request.Files != null)
            {
                var list = new List <KeyValuePair <string, string> >();

                foreach (string key in System.Web.HttpContext.Current.Request.Form.AllKeys)
                {
                    string value = System.Web.HttpContext.Current.Request.Form[key];

                    list.Add(new KeyValuePair <string, string>(key, value));
                }
                if (Request.Files.Count != 0)
                {
                    var file = Request.Files[0];
                    actualFileName = file.FileName;
                    fileName       = Guid.NewGuid() + Path.GetExtension(file.FileName);
                    size           = file.ContentLength;
                    file.SaveAs(Path.Combine(Server.MapPath(strpath), fileName));
                    MyProject.Controllers.ViewRequestController.UploadedFile f = new MyProject.Controllers.ViewRequestController.UploadedFile
                    {
                        FileName = actualFileName,
                        FilePath = fileName,
                    };
                }

                var custData = new List <CustomerInfo>();
                try
                {
                    if (list.Count > 0 && list != null)
                    {
                        Manufacturer = list.Find(x => x.Key == "Manufacturer").Value.ToString();
                        Model        = list.Find(x => x.Key == "Model").Value.ToString();
                        PartNo       = list.Find(x => x.Key == "PartNo").Value.ToString();
                        ProductType  = list.Find(x => x.Key == "ProductType").Value.ToString();
                        Spec         = list.Find(x => x.Key == "Spec").Value.ToString();
                        ProductID    = list.Find(x => x.Key == "ProductID").Value.ToString();
                        custData     = JsonConvert.DeserializeObject <List <CustomerInfo> >(list.Find(x => x.Key == "custlist").Value.ToString());
                        // var custData1 = list.Find(x => x.Key == "custlist").Value.ToString();
                    }
                    flag = true;

                    if (!string.IsNullOrEmpty(Manufacturer) && Manufacturer != "undefined")
                    {
                        productMasterDTO.ManufacturerId = Convert.ToInt64(Manufacturer);
                    }
                    if (!string.IsNullOrEmpty(ProductType) && ProductType != "undefined")
                    {
                        productMasterDTO.ProductTypeId = Convert.ToInt64(ProductType);
                    }
                    productMasterDTO.IsActive     = true;
                    productMasterDTO.Model        = Model;
                    productMasterDTO.PartNo       = PartNo;
                    productMasterDTO.Spec         = Spec;
                    productMasterDTO.ImageID      = actualFileName;
                    productMasterDTO.ImagePath    = fileName;
                    productMasterDTO.ImageType    = fileName;// Change name
                    productMasterDTO.ImageLength  = size.ToString();
                    productMasterDTO.strProductId = ProductID;
                    var Data = objData.AddUpdateProducts(custData, productMasterDTO);
                    return(new JsonResult {
                        Data = Data
                    });
                }
                catch (Exception ex)
                {
                    Message = "File Upload Failed!";
                    return(new JsonResult {
                        Data = null
                    });
                }
            }

            #endregion

            return(new JsonResult {
                Data = null
            });
        }