public FarmerDetails GetUser()
        {
            string userId = ((System.Security.Claims.ClaimsIdentity)User.Identity).
                            FindFirst("UserId").Value;
            FarmerDetails person = new FarmerDetails();

            using (MySqlConnection con = new MySqlConnection(connString))
            {
                //MySqlCommand cmd = new MySqlCommand("SELECT * FROM kamalanath_farmers.FarmerDetails WHERE farmerId=1; ", con);
                MySqlCommand cmd = new MySqlCommand("SELECT * FROM kamalana_farmers.FarmerDetails WHERE UserId='" + userId + "'; ", con);
                con.Open();
                var reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    person.FarmerId      = reader.GetInt32(reader.GetOrdinal("FarmerId"));
                    person.FirstName     = reader.GetString(reader.GetOrdinal("FirstName"));
                    person.UserName      = reader.GetString(reader.GetOrdinal("UserName"));
                    person.LastName      = reader.GetString(reader.GetOrdinal("LastName"));
                    person.Email         = reader.GetString(reader.GetOrdinal("Email"));
                    person.ContactNumber = reader.IsDBNull(reader.GetOrdinal("ContactNo")) ? null : reader.GetString(reader.GetOrdinal("ContactNo"));
                    person.AddressLine_1 = reader.IsDBNull(reader.GetOrdinal("AddressLine1")) ? null : reader.GetString(reader.GetOrdinal("AddressLine1"));
                    person.AddressLine_2 = reader.IsDBNull(reader.GetOrdinal("AddressLine2")) ? null : reader.GetString(reader.GetOrdinal("AddressLine2"));
                    person.City          = reader.IsDBNull(reader.GetOrdinal("City")) ? null : reader.GetString(reader.GetOrdinal("City"));
                    person.AboutMe       = reader.IsDBNull(reader.GetOrdinal("AboutMe")) ? null : reader.GetString(reader.GetOrdinal("AboutMe"));
                    person.roleType      = reader.IsDBNull(reader.GetOrdinal("RoleType")) ? 9 : reader.GetInt32(reader.GetOrdinal("RoleType"));

                    return(person);
                }
            }

            return(person);
        }
Example #2
0
        /// <summary>
        /// Common method to get Farmer details based on farmer id in productListing from database
        /// </summary>
        /// <param name="productListing"></param>
        /// <returns></returns>
        public async Task <FarmerDetails> GetFarmerDetailsByProductListing(ProductListingData productListing)
        {
            FarmerDetails farmer = new FarmerDetails();
            Users         user   = new Users();

            try
            {
                farmer = await(Task <FarmerDetails>)(from farmerDetails in _OrchardContext.FarmerDetails
                                                     join userData in _OrchardContext.Users on farmerDetails.UserId equals userData.UserId
                                                     where farmerDetails.FarmerId == productListing.FarmerId
                                                     select farmerDetails).FirstAsync();
                user = await(Task <Users>)(from farmerDetails in _OrchardContext.FarmerDetails
                                           join userDetails in _OrchardContext.Users on farmerDetails.UserId equals userDetails.UserId
                                           where farmerDetails.FarmerId == productListing.FarmerId
                                           select userDetails).FirstAsync();
            }
            catch (Exception)
            {
                throw new GeneralException("Something went wrong");
            }
            farmer.User = new Users()
            {
                UserFullName = user.UserFullName, Location = user.Location
            };
            return(farmer);
        }
        public FarmerDetails GetFarmerDetails(string FarmerKey)
        {
            DataSet ds = _Apdal.GetFarmerDetails(FarmerKey);

            FarmerDetails Reason = new FarmerDetails();

            if (ds != null && ds.Tables[0] != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                    {
                        Reason.FarmerId       = ds.Tables[0].Rows[i]["FarmerId"].ToString();
                        Reason.FarmerName     = ds.Tables[0].Rows[i]["FarmerName"].ToString();
                        Reason.RefernceSource = ds.Tables[0].Rows[i]["RefernceSource"].ToString();
                        Reason.FatherName     = ds.Tables[0].Rows[i]["FatherName"].ToString();
                        Reason.MobileNo       = ds.Tables[0].Rows[i]["MobNo"].ToString();
                        Reason.Email          = ds.Tables[0].Rows[i]["Email"].ToString();
                        Reason.StateId        = Convert.ToInt32(ds.Tables[0].Rows[i]["StateID"].ToString());
                        Reason.StateName      = ds.Tables[0].Rows[i]["StateName"].ToString();
                        Reason.DistrictId     = Convert.ToInt32(ds.Tables[0].Rows[i]["DistrictID"].ToString());
                        Reason.DistrictName   = ds.Tables[0].Rows[i]["DistrictName"].ToString();
                        Reason.BlockID        = Convert.ToInt32(ds.Tables[0].Rows[i]["BlockID"].ToString());
                        Reason.BlockName      = ds.Tables[0].Rows[i]["BlockName"].ToString();
                        Reason.VillageID      = Convert.ToInt32(ds.Tables[0].Rows[i]["VillageID"].ToString());
                        Reason.VillageName    = ds.Tables[0].Rows[i]["VillageName"].ToString();
                        Reason.Address        = ds.Tables[0].Rows[i]["Address"].ToString();
                        Reason.NearByVillage  = ds.Tables[0].Rows[i]["NearByVillage"].ToString();
                        Reason.IsActive       = Convert.ToBoolean(ds.Tables[0].Rows[i]["IsActive"].ToString());
                    }
                }
            }
            return(Reason);
        }
        public bool UpdateUser(FarmerDetails person)
        {
            string userId = ((System.Security.Claims.ClaimsIdentity)User.Identity).
                            FindFirst("UserId").Value;

            //FarmerDetails person = new FarmerDetails();
            using (MySqlConnection con = new MySqlConnection(connString))
            {
                //string temp = UPDATE `kamalanath_farmers`.`UserDetailsTable` SET `FirstName` = 'Tharindu', `LastName` = 'Dananjaya', `AddressLine_1` = 'Temp', `AddressLine_2` = 'Temp2', `City` = 'Matara', `RollId` = '1', `Phone` = '74747744', `Description` = 'I\'m WEll ' WHERE;
                string temp = "UPDATE `kamalana_farmers`.`FarmerDetails` SET `FirstName` = '" + person.FirstName +
                              "',`LastName` = '" + person.LastName +
                              "',`UserName` = '" + person.UserName +
                              "',`Email` = '" + person.Email +
                              "',`ContactNo` = '" + person.ContactNumber +
                              "',`AddressLine1` = '" + person.AddressLine_1 +
                              "',`AddressLine2` = '" + person.AddressLine_2 +
                              "',`City` = '" + person.City +
                              "',`AboutMe` = '" + person.AboutMe +
                              "',`RoleType` = '" + person.roleType +
                              "' WHERE (`UserId` = '" + userId + "');";

                MySqlCommand cmd = new MySqlCommand(temp, con);

                con.Open();
                cmd.ExecuteNonQuery();
            }

            return(true);
        }
Example #5
0
        /// <summary>
        /// Method to add prdouctListings
        /// </summary>
        /// <param name="productListingData"></param>
        /// <returns></returns>
        public async Task <bool> AddProductListings(ProductListingData productListingData)
        {
            try
            {
                int           userId = productListingData.FarmerId;
                FarmerDetails farmer = await _ApnaAaharContext.FarmerDetails.SingleOrDefaultAsync(farmerFound => farmerFound.UserId == userId);

                int FramerId = farmer.FarmerId;
                productListingData.FarmerId = FramerId;
                int rowAffected = 0;
                _ApnaAaharContext.Add(productListingData);
                rowAffected = await _ApnaAaharContext.SaveChangesAsync();

                if (rowAffected == 0)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            catch (SqlException ex)
            {
                throw new AnySqlException("Internal Error Occured!", ex);
            }
            catch (Exception ex)
            {
                throw new GeneralException("Unchecked error occured", ex);
            }
        }
Example #6
0
        public async Task AddFarmerAsCommunity_UniqueDetails_HappyFlow()
        {
            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId = 5678,
                User     = new Users()
                {
                    UserFullName = "smith",
                    PhoneNumber  = "7987569878",
                    Email        = "*****@*****.**",
                    Location     = "Hyderabad",
                    Password     = "******",
                    UserRole     = 1
                },
                Community = new CommunityDetails()
                {
                    CommunityName = "Remotecommunity"
                }
            };

            _orchard1Context.Users.Add(FarmerTestData());
            _orchard1Context.SaveChanges();
            var result = await farmerRepository.AddFarmerRegistrationDetails(farmer);

            Assert.AreEqual("Successfull", result);
        }
Example #7
0
        public async Task AddFarmerAsIndividual_InvalidUserDetails_BadFlow()
        {
            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId = 1234,
                User     = FarmerTestData(),
            };

            _farmerRepositoryMock.Setup(b => b.AddFarmerRegistrationDetails(It.IsAny <FarmerDetails>())).ThrowsAsync(new DataNotSavedException("Duplication"));
            await Assert.ThrowsExceptionAsync <DataNotSavedException>(async() => await _farmerServices.AddFarmerRegistrationDetails(farmer));
        }
Example #8
0
 public async Task <string> AddFarmerRegistrationDetails(FarmerDetails farmer)
 {
     try
     {
         return(await _FarmerData.AddFarmerRegistrationDetails(farmer));
     }
     catch (DataNotSavedException ex)
     {
         throw new DataNotSavedException(ex.Message);
     }
 }
Example #9
0
        public async Task AddFarmerAsIndividual_InvalidUserDetails_BadFlow()
        {
            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId = 1234,
                User     = FarmerTestData()
            };

            _orchard1Context.Users.Add(FarmerTestData());
            _orchard1Context.SaveChanges();

            await Assert.ThrowsExceptionAsync <DataNotSavedException>(async() => await farmerRepository.AddFarmerRegistrationDetails(farmer));
        }
Example #10
0
        public async Task AddFarmerAsIndividual_UniqueDetails_HappyFlow()
        {
            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId = 1234,
                User     = FarmerTestData(),
            };

            _farmerRepositoryMock.Setup(f => f.AddFarmerRegistrationDetails(It.IsAny <FarmerDetails>())).ReturnsAsync("Successfull");
            var testResult = await _farmerServices.AddFarmerRegistrationDetails(farmer);

            Assert.AreEqual("Successfull", testResult);
        }
Example #11
0
        public async Task AddFarmerAsCommunity_InvalidUserDetails_BadFlow()
        {
            CommunityDetails community = new CommunityDetails {
                CommunityName = "LocalCommunity"
            };
            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId  = 1234,
                User      = FarmerTestData(),
                Community = community
            };

            _farmerRepositoryMock.Setup(b => b.AddFarmerRegistrationDetails(It.IsAny <FarmerDetails>())).ThrowsAsync(new DataNotSavedException("Duplication"));
            await Assert.ThrowsExceptionAsync <DataNotSavedException>(async() => await _farmerServices.AddFarmerRegistrationDetails(farmer));
        }
Example #12
0
        public async Task AddFarmerAsCommunity_UniqueDetails_HappyFlow()
        {
            CommunityDetails community = new CommunityDetails {
                CommunityName = "LocalCommunity"
            };
            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId  = 1234,
                User      = FarmerTestData(),
                Community = community
            };

            _farmerRepositoryMock.Setup(f => f.AddFarmerRegistrationDetails(It.IsAny <FarmerDetails>())).ReturnsAsync("Successfull");
            var testResult = await _farmerServices.AddFarmerRegistrationDetails(farmer);

            Assert.AreEqual("Successfull", testResult);
        }
        public FarmerDetails GetFarmerDetails(string apiKey, string FarmerKey)
        {
            FarmerDetails fr = new FarmerDetails();

            if (apiKey == ConfigurationManager.AppSettings["reasonkey"])
            {
                try
                {
                    fr = _agentbal.GetFarmerDetails(FarmerKey);
                }
                catch (Exception ex)
                {
                    LogBal.ErrorLog(this.GetType().Name, MethodBase.GetCurrentMethod().Name, ex.Message, 0);
                }
            }
            return(fr);
        }
Example #14
0
        public async Task <bool> AcceptRequest(Users user)
        {
            try
            {
                FarmerDetails farmer = await _ApnaAaharContext.FarmerDetails.FirstOrDefaultAsync(users => users.UserId == user.UserId);

                farmer.IsApproved = true;
                if (_ApnaAaharContext.SaveChanges() > 0)
                {
                    return(true);
                }
                return(false);
            }
            catch (DbUpdateException ex)
            {
                throw new DbContextException("DataBase Exception occured", ex);
            }
        }
Example #15
0
        public async Task <ResponseModel> AddFarmerRegistrationDetails(FarmerDetails farmer)
        {
            ResponseModel responseModel = new ResponseModel();

            try
            {
                responseModel.ResponseMessage = await _farmerServices.AddFarmerRegistrationDetails(farmer);
            }
            catch (DataNotSavedException ex)
            {
                responseModel.ResponseMessage = ex.Message;
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            return(responseModel);
        }
Example #16
0
        private FarmerDetails FarmersData()
        {
            CommunityDetails community = new CommunityDetails {
                CommunityName = "LocalCommunity"
            };
            FarmerDetails farmerDetails = new FarmerDetails
            {
                FarmerId          = 1,
                UserId            = 1,
                IsApproved        = true,
                IsAccountDisabled = false,
                CommunityId       = 1,

                Community = community,
                User      = BuyersData()
            };

            return(farmerDetails);
        }
Example #17
0
        public async Task AddFarmerAsIndividual_InvalidFarmerId_BadFlow()
        {
            _orchard1Context.Database.EnsureDeleted();

            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId = 1234,
                User     = FarmerTestData()
            };
            FarmerDetails farmerDetails = new FarmerDetails()
            {
                FarmerId    = 1234,
                UserId      = 5,
                CommunityId = 6
            };

            _orchard1Context.Users.Add(FarmerTestData2());
            _orchard1Context.FarmerDetails.Add(farmerDetails);
            _orchard1Context.SaveChanges();

            await Assert.ThrowsExceptionAsync <DataNotSavedException>(async() => await farmerRepository.AddFarmerRegistrationDetails(farmer));
        }
Example #18
0
        public async Task AddFarmerAsCommunity_InvalidCommunityName_BadFlow()
        {
            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId  = 1234,
                User      = FarmerTestData(),
                Community = new CommunityDetails()
                {
                    CommunityName = "localcommunity"
                }
            };
            CommunityDetails communityDetails = new CommunityDetails
            {
                CommunityName = "localcommunity"
            };

            _orchard1Context.Users.Add(FarmerTestData2());
            _orchard1Context.CommunityDetails.Add(communityDetails);
            _orchard1Context.SaveChanges();

            await Assert.ThrowsExceptionAsync <DataNotSavedException>(async() => await farmerRepository.AddFarmerRegistrationDetails(farmer));
        }
Example #19
0
        public async Task AddFarmerAsIndividual_UniqueDetails_HappyFlow()
        {
            FarmerDetails farmer = new FarmerDetails
            {
                FarmerId = 6789,
                User     = new Users()
                {
                    UserFullName = "clary",
                    PhoneNumber  = "8967569878",
                    Email        = "*****@*****.**",
                    Location     = "Hyderabad",
                    Password     = "******",
                    UserRole     = 1
                }
            };

            _orchard1Context.Users.Add(FarmerTestData());
            _orchard1Context.SaveChanges();
            var result = await farmerRepository.AddFarmerRegistrationDetails(farmer);

            Assert.AreEqual("Successfull", result);
        }
Example #20
0
        /// <summary>
        /// method to get productListings by Farmer Id
        /// </summary>
        /// <param name="typeFilter"></param>
        /// <returns></returns>
        public async Task <IEnumerable <ProductListingData> > GetProductListingsFilteredByFarmer(Users user)
        {
            List <ProductListingData> productListings = new List <ProductListingData>();

            try
            {
                FarmerDetails farmer = await _ApnaAaharContext.FarmerDetails.FirstOrDefaultAsync(findFarmer => findFarmer.UserId == user.UserId);

                int farmerId = farmer.FarmerId;

                productListings = await _ApnaAaharContext.ProductListingData.Where(productListingData => productListingData.FarmerId == farmerId).Include(farmers => farmers.Farmer).ThenInclude(farmers => farmers.User).Include(productType => productType.ProductType).AsNoTracking().ToListAsync();

                foreach (ProductListingData productListing in productListings)
                {
                    productListing.Farmer.User.FarmerDetails      = null;
                    productListing.ProductType.ProductListingData = null;
                }
            }
            catch (Exception)
            {
                throw new GeneralException("Something went wrong");
            }
            return(productListings);
        }
Example #21
0
        public async Task <string> AddFarmerRegistrationDetails(FarmerDetails farmer)
        {
            Users userDataForEmailCheck = await _Orchard1Context.Users.FirstOrDefaultAsync(user => user.Email == farmer.User.Email);

            Users userDataForMobileNumberCheck = await _Orchard1Context.Users.FirstOrDefaultAsync(userData => userData.PhoneNumber == farmer.User.PhoneNumber);

            if (userDataForEmailCheck == null && userDataForMobileNumberCheck == null)
            {
                FarmerDetails farmerDetails = await _Orchard1Context.FarmerDetails.FirstOrDefaultAsync(farmerData => farmerData.FarmerId == farmer.FarmerId);

                if (farmer.Community == null && farmerDetails == null)
                {
                    try
                    {
                        Users user = farmer.User;
                        await _Orchard1Context.AddAsync(user);

                        farmer.UserId = user.UserId;
                        await _Orchard1Context.AddAsync(farmer);
                    }
                    catch (SqlException ex)
                    {
                        throw new DataNotSavedException("Data not saved", ex);
                    }
                }
                else if (farmer.Community != null && farmerDetails == null)
                {
                    CommunityDetails communityDetails = await _Orchard1Context.CommunityDetails.FirstOrDefaultAsync(community => community.CommunityName == farmer.Community.CommunityName);

                    if (communityDetails == null)
                    {
                        try
                        {
                            Users userData = farmer.User;
                            await _Orchard1Context.AddAsync(userData);

                            CommunityDetails communityData = farmer.Community;
                            await _Orchard1Context.AddAsync(communityData);

                            farmer.UserId      = userData.UserId;
                            farmer.CommunityId = communityData.CommunityId;
                            await _Orchard1Context.AddAsync(farmer);
                        }
                        catch (SqlException ex)
                        {
                            throw new DataNotSavedException("Data not saved", ex);
                        }
                    }
                    else
                    {
                        int isFarmerAdded = await _Orchard1Context.SaveChangesAsync();

                        if (isFarmerAdded == 0)
                        {
                            throw new DataNotSavedException("Community Name Already Exists");
                        }
                    }
                }
                else if (farmerDetails != null)
                {
                    int isFarmerAdded = await _Orchard1Context.SaveChangesAsync();

                    if (isFarmerAdded == 0)
                    {
                        throw new DataNotSavedException("FarmerId already exists");
                    }
                }
            }
            else
            {
                int isFarmerAdded = await _Orchard1Context.SaveChangesAsync();

                if (isFarmerAdded == 0)
                {
                    throw new DataNotSavedException("Duplication");
                }
            }
            int isDataAdded = await _Orchard1Context.SaveChangesAsync();

            if (isDataAdded > 0)
            {
                return("Successfull");
            }
            else
            {
                throw new DataNotSavedException("Duplication");
            }
        }