示例#1
0
        public async Task <bool> AddUserRegistrationDetails(Users user)
        {
            int isUserDataSaved = 0;

            try
            {
                await _ApnaAaharContext.AddAsync(user);

                isUserDataSaved = await _ApnaAaharContext.SaveChangesAsync();

                if (isUserDataSaved == 0)
                {
                    return(false);
                }
            }
            catch (DbUpdateException ex)
            {
                throw new DataNotSavedException("Failed to save details", ex);
            }
            catch (Exception ex)
            {
                throw ex;
            }

            return(true);
        }
示例#2
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");
            }
        }