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");
        }
        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"));
            }
        }