Ejemplo n.º 1
0
        public async Task <IHttpActionResult> GetvendorById(int id)
        {
            VendormasterModel status = new VendormasterModel();

            status = await _rfqBusenessAcess.GetvendorById(id);

            return(Ok(status));
        }
Ejemplo n.º 2
0
 public IHttpActionResult addNewVendor([FromBody] VendormasterModel vendor)
 {
     return(Ok(this._mprBusenessAcess.addNewVendor(vendor)));
 }
Ejemplo n.º 3
0
 public int addNewVendor(VendormasterModel vendor)
 {
     return(this._mprDataAcess.addNewVendor(vendor));
 }
Ejemplo n.º 4
0
        public IHttpActionResult uploadVendorData()
        {
            try
            {
                var    httpRequest    = HttpContext.Current.Request;
                var    serverPath     = HttpContext.Current.Server.MapPath("~/SCMDocs");
                string parsedFileName = "";
                if (httpRequest.Files.Count > 0)
                {
                    var Id         = httpRequest.Files.AllKeys[0];
                    var postedFile = httpRequest.Files[0];
                    parsedFileName = string.Format(DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MMM") + "\\" + Id + "\\" + ToValidFileName(postedFile.FileName));
                    serverPath     = serverPath + string.Format("\\" + DateTime.Now.Year.ToString() + "\\" + DateTime.Now.ToString("MMM")) + "\\" + Id;
                    var filePath = Path.Combine(serverPath, ToValidFileName(postedFile.FileName));
                    if (!Directory.Exists(serverPath))
                    {
                        Directory.CreateDirectory(serverPath);
                    }
                    postedFile.SaveAs(filePath);


                    DataTable dtexcel    = new DataTable();
                    bool      hasHeaders = false;
                    string    HDR        = hasHeaders ? "Yes" : "No";
                    string    strConn;
                    if (filePath.Substring(filePath.LastIndexOf('.')).ToLower() == ".xlsx")
                    {
                        strConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=" + HDR + ";IMEX=0\"";
                    }
                    else
                    {
                        strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filePath + ";Extended Properties=\"Excel 8.0;HDR=" + HDR + ";IMEX=0\"";
                    }

                    OleDbConnection conn = new OleDbConnection(strConn);
                    conn.Open();
                    DataTable schemaTable = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });

                    DataRow schemaRow = schemaTable.Rows[0];
                    string  sheet     = schemaRow["TABLE_NAME"].ToString();
                    if (!sheet.EndsWith("_"))
                    {
                        string           query   = "SELECT  * FROM [Sheet1$]";
                        OleDbDataAdapter daexcel = new OleDbDataAdapter(query, conn);
                        dtexcel.Locale = CultureInfo.CurrentCulture;
                        daexcel.Fill(dtexcel);
                    }

                    conn.Close();
                    int          iSucceRows = 0;
                    YSCMEntities obj        = new YSCMEntities();
                    foreach (DataRow row in dtexcel.Rows)
                    {
                        var          vendorcode   = row["Vendor Code"].ToString();
                        VendorMaster vendorMaster = obj.VendorMasters.Where(li => li.VendorCode == vendorcode).FirstOrDefault();
                        if (vendorMaster != null)
                        {
                            VendormasterModel vendorModel = new VendormasterModel();
                            vendorModel.Vendorid   = vendorMaster.Vendorid;
                            vendorModel.VendorName = row["Vendor Name"].ToString();
                            string Emailids = "";
                            if (!string.IsNullOrEmpty(row["Email Id 1"].ToString()))
                            {
                                Emailids = row["Email Id 1"].ToString();
                            }
                            if (!string.IsNullOrEmpty(row["Email Id 2"].ToString()))
                            {
                                Emailids += "," + row["Email Id 2"].ToString();
                            }
                            if (!string.IsNullOrEmpty(row["Email Id 3"].ToString()))
                            {
                                Emailids += "," + row["Email Id 3"].ToString();
                            }
                            if (!string.IsNullOrEmpty(row["Email Id 4"].ToString()))
                            {
                                Emailids += "," + row["Email Id 4"].ToString();
                            }

                            vendorModel.Emailid       = Emailids;
                            vendorModel.ContactNumber = row["contact number"].ToString();
                            vendorModel.ContactPerson = row["contact person"].ToString();
                            this._mprBusenessAcess.addNewVendor(vendorModel);
                        }
                    }


                    int succRecs = iSucceRows;
                }
                return(Ok(parsedFileName));
            }
            catch (Exception e)
            {
                log.ErrorMessage("MPRController", "uploadVendorData", e.Message.ToString());
                return(Ok(e));
            }
        }