Пример #1
0
        public IHttpActionResult PuttblFarmer(int id, tblFarmer tblFarmer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != tblFarmer.FarmerId)
            {
                return(BadRequest());
            }

            db.Entry(tblFarmer).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!tblFarmerExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #2
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));
        }
Пример #3
0
        public IHttpActionResult Post([FromUri] int id, int adminid)
        {
            tblFarmer tblFarmer = db.tblFarmers.Find(id);

            tblFarmer.FarmerApproved  = true;
            tblFarmer.ApprovalAdminId = adminid;
            db.Entry(tblFarmer).State = EntityState.Modified;
            db.SaveChanges();
            return(Ok("OK"));
        }
Пример #4
0
        public IHttpActionResult GettblFarmer(int id)
        {
            tblFarmer tblFarmer = db.tblFarmers.Find(id);

            if (tblFarmer == null)
            {
                return(NotFound());
            }

            return(Ok(tblFarmer));
        }
Пример #5
0
        public IHttpActionResult PosttblFarmer(tblFarmer tblFarmer)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.tblFarmers.Add(tblFarmer);
            db.SaveChanges();

            return(CreatedAtRoute("DefaultApi", new { id = tblFarmer.FarmerId }, tblFarmer));
        }
Пример #6
0
        public IHttpActionResult DeletetblFarmer(int id)
        {
            tblFarmer tblFarmer = db.tblFarmers.Find(id);

            if (tblFarmer == null)
            {
                return(NotFound());
            }

            db.tblFarmers.Remove(tblFarmer);
            db.SaveChanges();

            return(Ok(tblFarmer));
        }
Пример #7
0
        public HttpResponseMessage Post(tblFarmer farmer)
        {
            DbContextTransaction transaction = entities.Database.BeginTransaction();

            try
            {
                entities.sp_approveFarmer(farmer.fId, farmer.ApprovedBy, farmer.ApprovedDate, farmer.fPassword, farmer.fEmailId);
                entities.SaveChanges();
                transaction.Commit();
            }
            catch (Exception)
            {
                transaction.Rollback();
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Not able to approve the user"));
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Пример #8
0
        public HttpResponseMessage Getid([FromUri] string email, string user)
        {
            if (user == "admin")
            {
                List <tblAdmin> resadmin    = db.tblAdmins.ToList();
                tblAdmin        outputadmin = new tblAdmin();
                foreach (tblAdmin item in resadmin)
                {
                    if (item.AdminEmail.Equals(email))
                    {
                        outputadmin = item; break;
                    }
                }
                return(Request.CreateResponse(HttpStatusCode.OK, outputadmin.AdminId));
            }
            if (user == "farmer")
            {
                List <tblFarmer> res = db.tblFarmers.ToList();

                tblFarmer output = new tblFarmer();
                foreach (tblFarmer item in res)
                {
                    if (item.FarmerEmail == email)
                    {
                        output = item; break;
                    }
                }
                return(Request.CreateResponse(HttpStatusCode.OK, output.FarmerId));
            }

            List <tblBidder> resbid = db.tblBidders.ToList();

            tblBidder outputbid = new tblBidder();

            foreach (tblBidder item in resbid)
            {
                if (item.BidderEmail.Equals(email))
                {
                    outputbid = item; break;
                }
            }
            return(Request.CreateResponse(HttpStatusCode.OK, outputbid.BidderId));
        }
        public HttpResponseMessage Reset_Password(string email, string password)
        {
            tblUser user = entities.tblUsers.Where(f => f.EmailId == email).FirstOrDefault();

            try
            {
                if (user != null)
                {
                    user.Password = Pass.ConvertToEncrypt(password);
                    entities.SaveChanges();

                    if (user.fId != null)
                    {
                        tblFarmer farmer = entities.tblFarmers.Where(f => f.fId == user.fId).FirstOrDefault();
                        farmer.fPassword = Pass.ConvertToEncrypt(password);
                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK, "Password updated"));
                    }
                    else if (user.bId != null)
                    {
                        tblBidder bidder = entities.tblBidders.Where(b => b.bId == user.bId).FirstOrDefault();
                        bidder.bPassword = Pass.ConvertToEncrypt(password);
                        entities.SaveChanges();
                        return(Request.CreateResponse(HttpStatusCode.OK, "Password updated"));
                    }
                    else
                    {
                        return(Request.CreateResponse(HttpStatusCode.OK, "Password updated for admin"));
                    }
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, "User not found"));
                }
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotModified, "Password not updated"));
            }


            // return Request.CreateResponse(HttpStatusCode.NotFound, "Password updated for admin");
        }
Пример #10
0
        public HttpResponseMessage approveclaim(DateTime dateofloss, tblInsurance insurance)
        {
            DbContextTransaction transaction = entities.Database.BeginTransaction();

            try
            {
                var result = entities.sp_validateClaim(insurance.DateofApplication, dateofloss, insurance.FarmerId, insurance.CropType).FirstOrDefault();
                entities.sp_updateClaim(Convert.ToInt32(insurance.InsuranceApplicationId), Convert.ToInt32(result));
                entities.SaveChanges();
                transaction.Commit();
                tblFarmer farmer = entities.tblFarmers.Where(fa => fa.fId == insurance.FarmerId).FirstOrDefault();
                if (result == 1)
                {
                    EmailModel email = new EmailModel();
                    HttpClient http  = new HttpClient();
                    http.BaseAddress = new Uri("http://localhost:61674/api/Email");

                    email.to      = farmer.fEmailId;
                    email.subject = "Insurace Claim approved";
                    email.body    = "your policy number of" + insurance.InsuranceApplicationId + "\t is approved Money will be credited in you account number:" + farmer.fAccountNo;

                    var consumewebApi = http.PostAsJsonAsync <EmailModel>("email", email);
                }
                else
                {
                    EmailModel email = new EmailModel();
                    HttpClient http  = new HttpClient();
                    http.BaseAddress = new Uri("http://localhost:61674/api/Email");
                    email.to         = farmer.fEmailId;

                    email.subject = "Insurace Claim NOT approved";
                    email.body    = "your policy number of" + insurance.InsuranceApplicationId + "\t Is Expired, you are not allowed to CLAIM";
                    var consumewebApi = http.PostAsJsonAsync <EmailModel>("email", email);
                }
            }
            catch (Exception e)
            {
                transaction.Rollback();
                return(Request.CreateErrorResponse(HttpStatusCode.Ambiguous, e.Message));
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Пример #11
0
 public HttpResponseMessage RejectFarmer(string message, tblFarmer farmer)
 {
     try
     {
         EmailModel mail = new EmailModel();
         mail.to      = farmer.fEmailId;
         mail.subject = "Application Rejected";
         mail.body    = "Your account not approved because of follwing reasons" + message + "Kindly register again";
         HttpClient http = new HttpClient();
         http.BaseAddress = new Uri("http://localhost:61674/api/Email");
         var consumewebApi = http.PostAsJsonAsync <EmailModel>("email", mail);
         entities.Entry(farmer).State = System.Data.Entity.EntityState.Deleted;
         entities.SaveChanges();
     }
     catch (Exception)
     {
         return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Email Not Found "));
     }
     return(Request.CreateResponse(HttpStatusCode.OK));
 }
        public IHttpActionResult ApproveAuctionAdmin([FromUri] int id, int adminid)
        {
            tblBidding tblBidding = db.tblBiddings.Find(id);

            tblBidding.ApprovalAdminId = adminid;
            tblCropRequest tblCropRequest = db.tblCropRequests.Find(tblBidding.RequestId);
            tblFarmer      tblFarmer      = db.tblFarmers.Find(tblCropRequest.FarmerId);
            tblSale        tblSale        = new tblSale();

            tblSale.FarmerId           = tblFarmer.FarmerId;
            tblSale.BidderId           = tblBidding.BidderId;
            tblSale.Quantity           = (int?)tblCropRequest.Quantity;
            tblSale.CropName           = tblCropRequest.CropName;
            tblSale.MinSalePrice       = tblBidding.InitialPrice;
            tblSale.TotalPrice         = tblBidding.CurrentBidPrice;
            tblSale.SaleDate           = DateTime.Now.Date;
            tblSale.ApprovalAdminId    = adminid;
            db.Entry(tblBidding).State = EntityState.Modified;

            db.tblSales.Add(tblSale);
            db.SaveChanges();
            return(Ok("OK"));
        }
Пример #13
0
        public HttpResponseMessage Post(tblFarmer farmer)
        {
            DbContextTransaction transaction = entities.Database.BeginTransaction();

            try
            {
                entities.sp_approveFarmer(farmer.fId, farmer.ApprovedBy, farmer.ApprovedDate, farmer.fPassword, farmer.fEmailId);
                entities.SaveChanges();
                EmailModel mail = new EmailModel();
                mail.to      = farmer.fEmailId;
                mail.subject = "Account Activated";
                mail.body    = "username:"******"\n password:"******"http://localhost:61674/api/Email");
                var consumewebApi = http.PostAsJsonAsync <EmailModel>("email", mail);
                transaction.Commit();
            }
            catch (Exception)
            {
                transaction.Rollback();
                return(Request.CreateErrorResponse(HttpStatusCode.Conflict, "Not able to approve the user"));
            }
            return(Request.CreateResponse(HttpStatusCode.OK));
        }
Пример #14
0
        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 (dbProjectEntities db = new dbProjectEntities())
            {
                #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 (dbProjectEntities db1 = new dbProjectEntities())
                    {
                        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 (dbProjectEntities db1 = new dbProjectEntities())
                    {
                        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"));
        }
        public HttpResponseMessage Register()
        {
            DbContextTransaction transaction = entities.Database.BeginTransaction();

            string imageName  = null;
            string imageName1 = null;
            string imageName2 = null;



            var httpRequest = HttpContext.Current.Request;

            //Upload Image
            try
            {
                var postedFile  = httpRequest.Files["Aadhar"];
                var postedFile1 = httpRequest.Files["Pan"];
                var postedFile2 = httpRequest.Files["Certificate"];


                //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);

                imageName2 = new String(Path.GetFileNameWithoutExtension(postedFile2.FileName).Take(10).ToArray()).Replace(" ", "-");
                imageName2 = imageName2 + DateTime.Now.ToString("yymmssfff") + Path.GetExtension(postedFile2.FileName);
                var filePath2 = HttpContext.Current.Server.MapPath("~/Image/" + imageName2);
                postedFile2.SaveAs(filePath2);


                tblFarmer f = new tblFarmer();
                //Save to db
                using (dbFarmerScheme3Entities db = new dbFarmerScheme3Entities())
                {
                    string email = httpRequest["Email"];
                    var    e     = db.tblFarmers.Where(x => x.fEmailId == email).FirstOrDefault();


                    if (e == null)
                    {
                        string acc = httpRequest["AccountNo"];
                        var    a   = db.tblFarmers.Where(x => x.fAccountNo == acc).FirstOrDefault();
                        if (a == null)
                        {
                            try
                            {
                                f.fUserName  = httpRequest["Username"];
                                f.fContactNo = httpRequest["Contact"];
                                f.fEmailId   = httpRequest["Email"];
                                f.fAddress   = httpRequest["Address"];
                                f.fCity      = httpRequest["City"];
                                f.fState     = httpRequest["State"];
                                f.fPincode   = httpRequest["Pincode"];
                                f.fLandArea  = Convert.ToSingle(httpRequest["LArea"]);

                                f.fLandAddress = httpRequest["LAddress"];
                                f.fLandPincode = httpRequest["LPincode"];
                                f.fAccountNo   = httpRequest["AccountNo"];
                                f.fIFSCcode    = httpRequest["ifsccode"];
                                f.fAadhar      = filePath;
                                f.fPan         = filePath1;
                                f.fCertificate = filePath2;

                                f.fPassword = Pass.ConvertToEncrypt(httpRequest["Password"]);

                                f.StatusOfFarmerDocx = "pending";

                                entities.tblFarmers.Add(f);
                                entities.SaveChanges();


                                transaction.Commit();
                            }
                            catch (Exception)
                            {
                                transaction.Rollback();
                                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Data not Inserted"));
                            }
                        }
                        else
                        {
                            return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Account No already exist"));
                        }
                    }
                    else
                    {
                        return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Email already exist"));
                    }
                }
                return(Request.CreateResponse(HttpStatusCode.Created, "Successfully Registered"));
            }
            catch (Exception)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "File size should be less than 2MB"));
            }
        }