Example #1
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 #2
0
        public async Task <bool> UpdateProductMsp(ProductType productType)
        {
            int         isDataSaved = 0;
            ProductType productData = await _ApnaAaharContext.ProductType.FindAsync(productType.ProductTypeId);

            if (productData != null)
            {
                productData.Msp = productType.Msp;
            }
            try
            {
                isDataSaved = await _ApnaAaharContext.SaveChangesAsync();
            }
            catch (DbUpdateException)
            {
                throw new DataNotSavedException("unable to save data");
            }
            catch (Exception)
            {
                throw new DataNotSavedException("unable to save data");
            }
            if (isDataSaved > 0)
            {
                return(true);
            }
            return(false);
        }
Example #3
0
        public async Task <int> UpdateUserLocation(UpdateModel data)
        {
            try
            {
                if (data.Location != null)
                {
                    Users user = await _ApnaAaharContext.Users.FindAsync(data.UserId);

                    if (user != null)
                    {
                        user.Location = data.Location.Trim();
                    }
                }
                return(await _ApnaAaharContext.SaveChangesAsync());
            }
            catch (DbUpdateException ex)
            {
                throw new DbContextException("DataBase exception Occured", ex);
            }
            catch (Exception ex)
            {
                throw new GeneralException("Non DataBase exception Occured", ex);
            }
        }
Example #4
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");
            }
        }