Example #1
0
        public HttpResponseMessage Post(tblBid bid)
        {
            DbContextTransaction transaction = entities.Database.BeginTransaction();

            try
            {
                entities.sp_approveBid(bid.bId, bid.CropId);
                entities.SaveChanges();
                tblCropForSale crop   = entities.tblCropForSales.Where(c => c.CropId == bid.CropId).FirstOrDefault();
                tblFarmer      farmer = entities.tblFarmers.Where(f => f.fId == crop.FarmerId).FirstOrDefault();
                EmailModel     mail   = new EmailModel();
                mail.to      = farmer.fEmailId;
                mail.subject = "Crop Sold ";
                mail.body    = "Your crop sold id" + bid.CropId + "\t of type\t" + crop.CropType + "is sold for  amount " +
                               bid.BidAmount + "Rs/-;\n money will be credited after crop is shipped";
                HttpClient http = new HttpClient();
                http.BaseAddress = new Uri("http://localhost:61674/api/Email");
                var consumewebApi = http.PostAsJsonAsync <EmailModel>("email", mail);
                //Sending confirmation to bidder
                EmailModel bidderMail = new EmailModel();
                tblBidder  bidder     = entities.tblBidders.Where(b => bid.BidderId == b.bId).FirstOrDefault();
                bidderMail.to      = bidder.bEmailId;
                bidderMail.subject = "Congrats..! Your Bid Cinfirmed";
                bidderMail.body    = "your bid is confirmed for crop id" + bid.CropId + "with Amount Of" + bid.BidAmount + "<button>MakePaymet</button>";

                var consumewebApi2 = http.PostAsJsonAsync <EmailModel>("email", bidderMail);
                transaction.Commit();
            }
            catch (Exception)
            {
                transaction.Rollback();
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Something went Wrong Try to bid again"));
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Example #2
0
        public HttpResponseMessage AddCropDetails()
        {
            string document    = null;
            var    httpRequest = HttpContext.Current.Request;

            var postedFile = httpRequest.Files["SPhCert"];

            document = new String(Path.GetFileNameWithoutExtension(postedFile.FileName).Take(15).ToArray()).Replace(" ", "-");
            document = document + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile.FileName);
            var filePath = HttpContext.Current.Server.MapPath("~/Image/" + document);

            postedFile.SaveAs(filePath);

            tblCropForSale cropForSale = new tblCropForSale();

            cropForSale.SoilPhCertificate = filePath;
            cropForSale.CropType          = httpRequest["croptype"];
            cropForSale.CropName          = httpRequest["cropname"];
            cropForSale.Quantity          = Convert.ToInt32(httpRequest["quantity"]);
            cropForSale.FertilizerType    = httpRequest["fertilizertype"];

            cropForSale.StatusOfCropSaleReq = "pending";
            var x = httpRequest["farmerid"];

            cropForSale.FarmerId = Convert.ToInt32(x);

            // cropForSale.FarmerId = Convert.ToInt32(httpRequest["farmerid"]);

            DbContextTransaction transaction = entities.Database.BeginTransaction();

            if (ModelState.IsValid)
            {
                try
                {
                    entities.sp_Place_Request(cropForSale.FarmerId, cropForSale.CropType, cropForSale.CropName, cropForSale.Quantity,
                                              cropForSale.FertilizerType, cropForSale.SoilPhCertificate);
                    entities.SaveChanges();
                    transaction.Commit();
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Could not Place Request"));
                }
            }

            return(Request.CreateResponse(HttpStatusCode.Created, cropForSale));
        }
Example #3
0
        public HttpResponseMessage Post(tblCropForSale sale)
        {
            DbContextTransaction transaction = entities.Database.BeginTransaction();

            try
            {
                entities.sp_approvesale(sale.CropId, sale.CropType, sale.CropName);
                entities.SaveChanges();
                transaction.Commit();
            }
            catch (Exception)
            {
                transaction.Rollback();
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Not able to approve the user"));
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }