public HttpResponseMessage WayTwo() { string imageName = ""; string Qty = ""; var httpRequest = HttpContext.Current.Request; //Upload Image var postedFile = httpRequest.Files["Image"]; //Create custom filename imageName = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-"); imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName); var filePath = HttpContext.Current.Server.MapPath("~/Image/" + imageName); postedFile.SaveAs(filePath); //Save to DB using (dbProjectEntities1 db = new dbProjectEntities1()) { tblCropRequest cpr = new tblCropRequest(); cpr.SoilPhCertificate = imageName; cpr.CropType = httpRequest["CropType"]; cpr.CropName = httpRequest["CropName"]; cpr.FertilizerType = httpRequest["FertilizerType"]; Qty = (httpRequest["Quantity"]); //Quantity = 25 cpr.Quantity = Convert.ToInt32(Qty); cpr.Farmerid = Convert.ToInt32(httpRequest["FarmerID"]); cpr.CropApproved = false; db.tblCropRequests.Add(cpr); db.SaveChanges(); } return(Request.CreateResponse(HttpStatusCode.Created)); }
public HttpResponseMessage getSaleHistory([FromUri] int id, string usertype) { using (var db = new dbProjectEntities1()) { if (usertype.Equals("farmer")) { var sales = (from s in db.tblSales where s.Farmerid == id && s.ApprovalAdminId != null select s).ToList(); if (sales.Count > 0) { return(Request.CreateResponse(HttpStatusCode.OK, sales)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Data not found")); } } else if (usertype.Equals("bidder")) { var sales = (from s in db.tblSales where s.Bidderid == id && s.ApprovalAdminId != null select s).ToList(); if (sales.Count > 0) { return(Request.CreateResponse(HttpStatusCode.OK, sales)); } else { return(Request.CreateResponse(HttpStatusCode.NotFound, "Data not found")); } } else { return(Request.CreateResponse(HttpStatusCode.OK)); } } }
public IHttpActionResult WayTwo() { string imageName = ""; string imageName1 = ""; string Qty = ""; var httpRequest = HttpContext.Current.Request; //Upload Image var postedFile = httpRequest.Files["Image"]; var postedFile1 = httpRequest.Files["Image1"]; //Create custom filename imageName = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-"); imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName); var filePath = HttpContext.Current.Server.MapPath("~/Image/" + imageName); postedFile.SaveAs(filePath); imageName1 = new String(Path.GetFileNameWithoutExtension(postedFile1.FileName).Take(10).ToArray()).Replace(" ", "-"); imageName1 = imageName1 + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile1.FileName); var filePath1 = HttpContext.Current.Server.MapPath("~/Image/" + imageName1); postedFile1.SaveAs(filePath1); tblBidder br = new tblBidder(); //Save to DB using (dbProjectEntities1 db = new dbProjectEntities1()) { List <tblBidder> bidders = db.tblBidders.ToList(); List <tblBank> banks = db.tblBanks.ToList(); foreach (tblBidder tblBidder1 in bidders) { if (tblBidder1.BidderEmail == httpRequest["BidderEmail"]) { return(Ok("Email")); } } foreach (tblBank tblBank1 in banks) { if (tblBank1.AccountNo == httpRequest["AccountNo"]) { return(Ok("Account")); } } try { #region saving details into db br.BidderAadhar = imageName; br.BidderTradeLicense = imageName1; br.BidderName = httpRequest["BidderName"]; br.BidderEmail = httpRequest["BidderEmail"]; br.BidderContactNo = httpRequest["BidderContactNo"]; br.BidderAddress = httpRequest["BidderAddress"]; br.BidderCity = httpRequest["BidderCity"]; br.BidderState = httpRequest["BidderState"]; br.BidderPincocde = httpRequest["BidderPincocde"]; br.BidderPassword = httpRequest["BidderPassword"]; byte[] encData_byte = new byte[br.BidderPassword.Length]; encData_byte = System.Text.Encoding.UTF8.GetBytes(br.BidderPassword); string encodedpassword = Convert.ToBase64String(encData_byte); br.BidderPassword = encodedpassword; br.BidderApproved = false; db.tblBidders.Add(br); db.SaveChanges(); List <tblBidder> res = db.tblBidders.ToList(); foreach (tblBidder item in res) { if (item.BidderEmail == br.BidderEmail) { bid = item.Bidderid; break; } } tblBank tb1 = new tblBank(); tb1.Farmerid = null; tb1.AccountNo = httpRequest["AccountNo"]; tb1.IFSC_Code = httpRequest["IFSC_Code"]; tb1.Bidderid = bid; db.tblBanks.Add(tb1); db.SaveChanges(); #endregion } catch { return(Ok("Error")); } } return(Ok("OK")); }
public IHttpActionResult WayTwo() { string imageName = ""; string imageName1 = ""; string Qty = ""; var httpRequest = HttpContext.Current.Request; //Upload Image var postedFile = httpRequest.Files["Image"]; var postedFile1 = httpRequest.Files["Image1"]; //Create custom filename imageName = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(10).ToArray()).Replace(" ", "-"); imageName = imageName + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName); var filePath = HttpContext.Current.Server.MapPath("~/Image/" + imageName); postedFile.SaveAs(filePath); imageName1 = new String(Path.GetFileNameWithoutExtension(postedFile1.FileName).Take(10).ToArray()).Replace(" ", "-"); imageName1 = imageName1 + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile1.FileName); var filePath1 = HttpContext.Current.Server.MapPath("~/Image/" + imageName1); //var filePath1 = HttpContext.Current.Server.MapPath("D:/Project_Angular/AgriFarmProj/src/assets/uploadeddocs/" + imageName1); postedFile1.SaveAs(filePath1); tblFarmer fmr = new tblFarmer(); //Save to DB using (dbProjectEntities1 db = new dbProjectEntities1()) { #region saving data into db List <tblFarmer> farmers = db.tblFarmers.ToList(); List <tblBank> banks = db.tblBanks.ToList(); foreach (tblFarmer tblFarmer1 in farmers) { if (tblFarmer1.FarmerEmail == httpRequest["FarmerEmail"]) { return(Ok("Email")); } } foreach (tblBank tblBank1 in banks) { if (tblBank1.AccountNo == httpRequest["AccountNo"]) { return(Ok("Account")); } } try { fmr.FarmerAadhar = imageName; fmr.FarmerCertificate = imageName1; fmr.FarmerName = httpRequest["FarmerName"]; fmr.FarmerContactNo = httpRequest["FarmerContactNo"]; fmr.FarmerAddress = httpRequest["FarmerAddress"]; fmr.FarmerCity = httpRequest["FarmerCity"]; fmr.FarmerState = httpRequest["FarmerState"]; fmr.FarmerPincocde = httpRequest["FarmerPincocde"]; fmr.FarmerEmail = httpRequest["FarmerEmail"]; fmr.FarmerPassword = httpRequest["FarmerPassword"]; fmr.FarmerApproved = false; byte[] encData_byte = new byte[fmr.FarmerPassword.Length]; encData_byte = System.Text.Encoding.UTF8.GetBytes(fmr.FarmerPassword); string encodedpassword = Convert.ToBase64String(encData_byte); fmr.FarmerPassword = encodedpassword; db.tblFarmers.Add(fmr); db.SaveChanges(); // db.SaveChanges(); /* * }*/ List <tblFarmer> res = db.tblFarmers.ToList(); foreach (tblFarmer item in res) { if (item.FarmerEmail == fmr.FarmerEmail) { fid = item.Farmerid; break; } } tblBank tb1 = new tblBank(); using (dbProjectEntities1 db1 = new dbProjectEntities1()) { tb1.Farmerid = fid; tb1.AccountNo = httpRequest["AccountNo"]; tb1.IFSC_Code = httpRequest["IFSC_Code"]; tb1.Bidderid = null; db1.tblBanks.Add(tb1); db1.SaveChanges(); // db.SaveChanges(); } tblFarmLand tb2 = new tblFarmLand(); using (dbProjectEntities1 db1 = new dbProjectEntities1()) { tb2.Farmerid = fid; tb2.FarmerLandArea = httpRequest["FarmerLandArea"]; tb2.FarmerLandAddress = httpRequest["FarmerLandAddress"]; tb2.FarmerLandPincode = httpRequest["FarmerLandPincode"]; db1.tblFarmLands.Add(tb2); db1.SaveChanges(); } #endregion } catch (Exception) { return(Ok("Error")); } } return(Ok("OK")); }