Esempio n. 1
0
        private void GetData(Devotee devotee)
        {
            try
            {
                string strFullAddress = devotee.Address + ", " + devotee.City + "," + devotee.State + "," + devotee.Country + ".";

                ReportParameter[] param = new ReportParameter[8];
                param[0] = new ReportParameter("ReceiptNumber", Convert.ToString(devotee.ReceiptNumber));
                param[1] = new ReportParameter("Address", strFullAddress);
                param[2] = new ReportParameter("AnnadhanamDate", devotee.AnadhanamDate.Date.ToString("dd-MMM-yyyy"));
                param[3] = new ReportParameter("ChequeNumber", (devotee.PaymentMode == PaymentMode.CASH ? "NIL" : devotee.ChequeNo));
                param[4] = new ReportParameter("ChequeDate", (devotee.PaymentMode == PaymentMode.CASH ? "NIL" : devotee.ChequeDate.Date.ToString("dd-MMM-yyyy")));
                param[5] = new ReportParameter("ChequeDrawnOn", (devotee.PaymentMode == PaymentMode.CASH ? "NIL" : devotee.ChequeDrawn));
                param[6] = new ReportParameter("NameOfDevotee", devotee.DevoteeName);
                param[7] = new ReportParameter("TodayDate", devotee.ReceiptCreatedDate.Date.ToString("dd-MMM-yyyy"));

                this.ReceiptReportViewer.LocalReport.SetParameters(param);
                this.ReceiptReportViewer.LocalReport.Refresh();
                this.ReceiptReportViewer.RefreshReport();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                Con.Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// The btnUpdate_Click.
        /// </summary>
        /// <param name="sender">The sender<see cref="object"/>.</param>
        /// <param name="e">The e<see cref="EventArgs"/>.</param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            List <Devotee> lstReceiptNumber = new List <Devotee>();

            lstReceiptNumber = SqlHelper.GetListOfReceiptNumberbyAnnaDhanamDate(dtAnadhanamDate.Value.Date);
            BookedCount      = SqlHelper.GetAnnadhanamDayCountByDate(dtAnadhanamDate.Value.Date);
            TotalCount       = SqlHelper.GetAnnadhanamTotalCountByDate(dtAnadhanamDate.Value.Date);
            if (BookedCount < TotalCount)
            {
                if (ValidateDevoteeDetails())
                {
                    Devotee devotee = AssignDevoteeDetails();
                    SqlHelper.UpdateAnnadhanam(devotee);
                    clear();
                }
            }
            else if (lstReceiptNumber?.Count > 0 && lstReceiptNumber.Exists(item => item.ReceiptNumber == Convert.ToInt32(txtReceiptNumber.Text)))
            {
                if (ValidateDevoteeDetails())
                {
                    Devotee devotee = AssignDevoteeDetails();
                    SqlHelper.UpdateAnnadhanam(devotee);
                    clear();
                }
            }
            else
            {
                MessageBox.Show("We have already issued " + TotalCount + " receipt for the Anadhanam Date (" + dtAnadhanamDate.Value.Date.ToString("dd-MMM-yyyy") + ") Please Choose Another Date!...", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Esempio n. 3
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            var devoteeObj = new Devotee
            {
                Id           = Convert.ToInt32(txtDevoteeId.Text),
                DevoteeName  = txtDevoteeName.Text,
                Prefix       = Convert.ToInt32(txtPrefixId.Text),
                Gothram      = txtGothram.Text,
                PhoneNumber  = txtPhoneNumber.Text,
                EmailId      = txtEmail.Text,
                DoorNumber   = txtDoorNumber.Text,
                AreaName     = txtAreaName.Text,
                City         = txtCity.Text,
                MandalName   = txtMandalName.Text,
                DistrictName = txtDistrictName.Text,
                StateName    = txtStateName.Text,
                OtherDetails = txtOtherDetails.Text
            };
            var devoteeDao = new DevoteesDao();
            int devoteeId  = devoteeDao.Update(devoteeObj);
            var tokenDAO   = new TokenDao();

            tkn.ServicePerformDate = Convert.ToDateTime(dtpPerformDate.Value);
            tkn.TokenStatus        = cmbTokenStatus.Text;
            tokenDAO.UpdateToken(tkn);
        }
Esempio n. 4
0
        /// <summary>
        /// The CreateAnnadhanam.
        /// </summary>
        /// <param name="devotee">The devotee<see cref="Devotee"/>.</param>
        internal static void CreateAnnadhanam(Devotee devotee)
        {
            if (devotee.PaymentMode == PaymentMode.CASH)
            {
                sqlQuery = "INSERT INTO tblAnnadhanamDetails(ReceiptNumber,DevoteeName,Address,CountryCode,Country,StateCode,State,CityCode,City,Amount,ReceiptCreatedDate,AnadhanamDate,Mode,ContactNumber)VALUES(@ReceiptNumber,@DevoteeName, @Address,@CountryCode,@Country,@StateCode,@State,@CityCode,@City,@Amount,@ReceiptCreatedDate,@AnadhanamDate,@Mode,@ContactNumber)";
            }
            else
            {
                sqlQuery = "INSERT INTO tblAnnadhanamDetails(ReceiptNumber,DevoteeName,Address,CountryCode,Country,StateCode,State,CityCode,City,Amount,ReceiptCreatedDate,AnadhanamDate,ChequeNo,ChequeDate,ChequeDrawn,Mode,ContactNumber)VALUES(@ReceiptNumber,@DevoteeName, @Address,@CountryCode,@Country,@StateCode,@State,@CityCode,@City,@Amount,@ReceiptCreatedDate,@AnadhanamDate,@ChequeNo,@ChequeDate,@ChequeDrawn,@Mode,@ContactNumber)";
            }

            DateTime dtAnadhanamDates = new DateTime(devotee.AnadhanamDate.Date.Year, devotee.AnadhanamDate.Date.Month, devotee.AnadhanamDate.Date.Day, 12, 0, 0);

            OpenSqlCeConnection();

            SqlCeCommand cm = new SqlCeCommand(sqlQuery, con);

            cm.Parameters.AddWithValue("@ReceiptNumber", devotee.ReceiptNumber);
            cm.Parameters.AddWithValue("@DevoteeName", devotee.DevoteeName);
            cm.Parameters.AddWithValue("@Address", devotee.Address);
            cm.Parameters.AddWithValue("@CountryCode", devotee.CountryCode);
            cm.Parameters.AddWithValue("@Country", devotee.Country);
            cm.Parameters.AddWithValue("@StateCode", devotee.StateCode);
            cm.Parameters.AddWithValue("@State", devotee.State);
            cm.Parameters.AddWithValue("@CityCode", devotee.CityCode);
            cm.Parameters.AddWithValue("@City", devotee.City);
            cm.Parameters.AddWithValue("@Amount", 500);
            cm.Parameters.AddWithValue("@ReceiptCreatedDate", DateTime.Now.Date);
            cm.Parameters.AddWithValue("@AnadhanamDate", dtAnadhanamDates);
            cm.Parameters.AddWithValue("@Mode", devotee.PaymentMode);
            cm.Parameters.AddWithValue("@ContactNumber", devotee.ContactNumber);

            if (devotee.PaymentMode == PaymentMode.CHEQUE)
            {
                cm.Parameters.AddWithValue("@ChequeNo", devotee.ChequeNo);
                cm.Parameters.AddWithValue("@ChequeDate", devotee.ChequeDate);
                cm.Parameters.AddWithValue("@ChequeDrawn", devotee.ChequeDrawn);
            }

            try
            {
                int intAffectedRow = cm.ExecuteNonQuery();
                con.Close();

                if (intAffectedRow > 0)
                {
                    MessageBox.Show("Anadhanam Created Sucessfully", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Receipt receiptForm = new Receipt(devotee);
                    receiptForm.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Insertion Failed", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 5
0
        private void btnAddService_Click(object sender, EventArgs e)
        {
            var selectedService = cmbServices.SelectedItem as Service;
            var token           = new Token();

            token.ServiceId   = selectedService.Id;
            token.ServiceName = selectedService.Name;
            token.Quantity    = Convert.ToInt32(txtQuantity.Text);
            token.TotalCost   = token.Quantity * Convert.ToDouble(txtCost.Text);
            token.CreatedBy   = App.LoggedInEmployee.Id;
            token.CreatedOn   = DateTime.Now;

            _selectedTokens.Add(token);
            mtxtServiceNumber.Clear();
            txtQuantity.Text = "1";
            mtxtServiceNumber.Focus();

            for (int i = 0; i < token.Quantity; i++)
            {
                var newDevotee = new Devotee();
                newDevotee.TokenIndex  = _selectedDevotees.Count + 1;
                newDevotee.ServiceName = token.ServiceName;
                newDevotee.Prefix      = 1;
                newDevotee.DevoteeName = string.Empty;
                newDevotee.Gothram     = string.Empty;

                _selectedDevotees.Add(newDevotee);
            }
        }
Esempio n. 6
0
 public int Update(Devotee devotee)
 {
     using (var db = new eTempleDbDB())
     {
         db.Update(devotee);
         return(devotee.Id);
     }
 }
Esempio n. 7
0
 private void btnGetDetails_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrWhiteSpace(txtReceiptNumber.Text))
     {
         Devotee devotee = SqlHelper.GetDevoteeDetails(txtReceiptNumber.Text);
         GetData(devotee);
     }
     else
     {
         MessageBox.Show("Enter Valid Receipt Number", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Esempio n. 8
0
 /// <summary>
 /// The btnPrint_Click.
 /// </summary>
 /// <param name="sender">The sender<see cref="object"/>.</param>
 /// <param name="e">The e<see cref="EventArgs"/>.</param>
 private void btnPrint_Click(object sender, EventArgs e)
 {
     BookedCount = SqlHelper.GetAnnadhanamDayCountByDate(dtAnadhanamDate.Value.Date);
     TotalCount  = SqlHelper.GetAnnadhanamTotalCountByDate(dtAnadhanamDate.Value.Date);
     if (BookedCount < TotalCount)
     {
         if (ValidateDevoteeDetails())
         {
             Devotee devotee = AssignDevoteeDetails();
             SqlHelper.CreateAnnadhanam(devotee);
             clear();
             txtReceiptNumber.Text = SqlHelper.GetLastReceiptNumber();
         }
     }
     else
     {
         MessageBox.Show("We have already issued " + TotalCount + " receipt for the Anadhanam Date (" + dtAnadhanamDate.Value.Date.ToString("dd-MMM-yyyy") + ") Please Choose Another Date!...", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Esempio n. 9
0
        /// <summary>
        /// The AssignDevoteeDetails.
        /// </summary>
        /// <returns>The <see cref="Devotee"/>.</returns>
        private Devotee AssignDevoteeDetails()
        {
            Devotee devotee = new Devotee();

            devotee.ReceiptNumber = Convert.ToInt32(txtReceiptNumber.Text);
            devotee.DevoteeName   = Convert.ToString(txtName.Text);
            devotee.Address       = Convert.ToString(txtAddress.Text);

            CountryDetails selCountry = (CountryDetails)cmbCountry.SelectedItem;

            devotee.CountryCode = Convert.ToInt32(selCountry.CountryID);
            devotee.Country     = Convert.ToString(selCountry.CountryName);

            StateDetails selState = (StateDetails)cmbState.SelectedItem;

            devotee.StateCode = Convert.ToInt32(selState.StateID);
            devotee.State     = Convert.ToString(selState.StateName);

            CityDetails selCity = (CityDetails)cmbCity.SelectedItem;

            devotee.CityCode = Convert.ToInt32(selCity.CityID);
            devotee.City     = Convert.ToString(selCity.CityName);

            devotee.Amount             = 500;
            devotee.ReceiptCreatedDate = DateTime.Now.Date;
            devotee.AnadhanamDate      = Convert.ToDateTime(dtAnadhanamDate.Value.Date);
            devotee.ContactNumber      = Convert.ToString(txtMobileNumber.Text);

            if (cmbPaymentMode.SelectedIndex == 1)
            {
                devotee.PaymentMode = PaymentMode.CHEQUE;
                devotee.ChequeNo    = Convert.ToString(txtChequeNumber.Text);
                devotee.ChequeDate  = Convert.ToDateTime(dtChequeDate.Value.Date);
                devotee.ChequeDrawn = Convert.ToString(txtDrawnOn.Text);
            }
            else
            {
                devotee.PaymentMode = PaymentMode.CASH;
            }

            return(devotee);
        }
Esempio n. 10
0
        public Receipt(Devotee devotee)
        {
            InitializeComponent();
            MaximizeBox = false;

            string strFullAddress = devotee.Address + ", " + devotee.City + "," + devotee.State + "," + devotee.Country + ".";

            ReportParameter[] param = new ReportParameter[8];
            param[0] = new ReportParameter("ReceiptNumber", Convert.ToString(devotee.ReceiptNumber));
            param[1] = new ReportParameter("Address", strFullAddress);
            param[2] = new ReportParameter("AnnadhanamDate", devotee.AnadhanamDate.ToString("dd-MMM-yyyy"));
            param[3] = new ReportParameter("ChequeNumber", (devotee.PaymentMode == PaymentMode.CASH ? "NIL" : devotee.ChequeNo));
            param[4] = new ReportParameter("ChequeDate", (devotee.PaymentMode == PaymentMode.CASH ? "NIL" : devotee.ChequeDate.ToString("dd-MMM-yyyy")));
            param[5] = new ReportParameter("ChequeDrawnOn", (devotee.PaymentMode == PaymentMode.CASH ? "NIL" : devotee.ChequeDrawn));
            param[6] = new ReportParameter("NameOfDevotee", devotee.DevoteeName);
            param[7] = new ReportParameter("TodayDate", DateTime.Now.ToString("dd-MMM-yyyy"));

            this.ReceiptReportViewer.LocalReport.SetParameters(param);
            this.ReceiptReportViewer.LocalReport.Refresh();
        }
Esempio n. 11
0
        /// <summary>
        /// The UpdateAnnadhanam.
        /// </summary>
        /// <param name="devotee">The devotee<see cref="Devotee"/>.</param>
        internal static void UpdateAnnadhanam(Devotee devotee)
        {
            DateTime dtAnadhanamDates = new DateTime(devotee.AnadhanamDate.Date.Year, devotee.AnadhanamDate.Date.Month, devotee.AnadhanamDate.Date.Day, 12, 0, 0);

            OpenSqlCeConnection();

            string paymentMode = string.Empty;

            if (devotee.PaymentMode == PaymentMode.CASH)
            {
                sqlQuery = "UPDATE tblAnnadhanamDetails Set DevoteeName='" + devotee.DevoteeName.Trim() + "',Address='" + devotee.Address + "',CountryCode=" + devotee.CountryCode + ",Country='" + devotee.Country + "',StateCode=" + devotee.StateCode + ",State='" + devotee.State + "',CityCode=" + devotee.CityCode + ",City='" + devotee.City + "',AnadhanamDate='" + dtAnadhanamDates.ToString("dd-MMM-yyyy HH:mm:ss") + "', Mode='" + devotee.PaymentMode + "',ContactNumber='" + devotee.ContactNumber + "' WHERE ReceiptNumber='" + devotee.ReceiptNumber.ToString() + "'";
            }
            else
            {
                sqlQuery = "UPDATE tblAnnadhanamDetails Set DevoteeName='" + devotee.DevoteeName.Trim() + "',Address='" + devotee.Address + "',CountryCode=" + devotee.CountryCode + ",Country='" + devotee.Country + "',StateCode=" + devotee.StateCode + ",State='" + devotee.State + "',CityCode=" + devotee.CityCode + ",City='" + devotee.City + "',AnadhanamDate='" + dtAnadhanamDates.ToString("dd-MMM-yyyy HH:mm:ss") + "',ChequeNo='" + devotee.ChequeNo + "',ChequeDate='" + devotee.ChequeDate + "',ChequeDrawn='" + devotee.ChequeDrawn + "',Mode='" + devotee.PaymentMode + "',ContactNumber='" + devotee.ContactNumber + "' WHERE ReceiptNumber='" + devotee.ReceiptNumber.ToString() + "'";
            }

            try
            {
                SqlCeCommand cm             = new SqlCeCommand(sqlQuery, con);
                int          intAffectedRow = cm.ExecuteNonQuery();
                con.Close();

                if (intAffectedRow > 0)
                {
                    MessageBox.Show("Anadhanam Updated Sucessfully", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Receipt receiptForm = new Receipt(devotee);
                    receiptForm.ShowDialog();
                }
                else
                {
                    MessageBox.Show("Updation Failed", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 12
0
        /// <summary>
        /// The LoadDevoteeDetails.
        /// </summary>
        /// <param name="strReceiptNumber">The strReceiptNumber<see cref="string"/>.</param>
        private void LoadDevoteeDetails(string strReceiptNumber)
        {
            try
            {
                Devotee devotee = SqlHelper.GetDevoteeDetails(strReceiptNumber);
                if (devotee?.ReceiptNumber != null)
                {
                    {
                        txtReceiptNumber.Text = Convert.ToString(devotee.ReceiptNumber);
                        txtName.Text          = Convert.ToString(devotee.DevoteeName);
                        txtAddress.Text       = Convert.ToString(devotee.Address);
                        txtMobileNumber.Text  = Convert.ToString(devotee.ContactNumber);

                        dtAnadhanamDate.Value = devotee.AnadhanamDate.Date;

                        lstCountryDetails = SqlHelper.GetCountryDetails();
                        string countryCode = lstCountryDetails.Where(x => x.CountryName == devotee.Country).Select(x => x.CountryID).FirstOrDefault();
                        cmbCountry.SelectedValue = countryCode;

                        lstStateDetails = SqlHelper.GetStateDetails(Convert.ToInt32(countryCode));
                        string stateCode = (from p in lstStateDetails where p.StateName.Contains(Convert.ToString(devotee.State).Trim()) select p.StateID).FirstOrDefault();
                        cmbState.SelectedValue = stateCode;

                        lstCityDetails = SqlHelper.GetCityDetails(Convert.ToInt32(stateCode));
                        string cityCode = lstCityDetails.Where(x => x.CityName == devotee.City).Select(x => x.CityID).FirstOrDefault();
                        cmbCity.SelectedValue = cityCode;

                        if (devotee.PaymentMode == PaymentMode.CHEQUE)
                        {
                            txtChequeNumber.Enabled = true;
                            txtDrawnOn.Enabled      = true;
                            dtChequeDate.Enabled    = true;

                            txtChequeNumber.Text = (!string.IsNullOrWhiteSpace(devotee.ChequeNo)) ? devotee.ChequeNo : string.Empty;
                            txtDrawnOn.Text      = (!string.IsNullOrWhiteSpace(devotee.ChequeDrawn)) ? devotee.ChequeDrawn : string.Empty;
                            if (devotee?.ChequeDate.Date != null)
                            {
                                DateTime dtPreviousChequeDate = Convert.ToDateTime(devotee.ChequeDate).Date;
                                if (dtPreviousChequeDate >= dtChequeDate.MinDate && dtPreviousChequeDate <= dtChequeDate.MinDate)
                                {
                                    dtChequeDate.Value = Convert.ToDateTime(devotee.ChequeDate).Date;
                                }
                            }
                            cmbPaymentMode.SelectedIndex = 1;
                        }
                        else
                        {
                            txtChequeNumber.Text         = devotee.ChequeNo;
                            txtDrawnOn.Text              = devotee.ChequeDrawn;
                            cmbPaymentMode.SelectedIndex = 0;
                            dtChequeDate.Value           = DateTime.Now.Date;

                            txtChequeNumber.Enabled = false;
                            txtDrawnOn.Enabled      = false;
                            dtChequeDate.Enabled    = false;
                        }
                    }
                    this.txtReceiptNumber.Enabled = false;
                }
                else
                {
                    MessageBox.Show("Enter Valid Receipt / Mobile Number", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.txtReceiptNumber.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// The GetData.
        /// </summary>
        /// <param name="strReceiptNumber">The strReceiptNumber<see cref="string"/>.</param>
        /// <returns>The <see cref="DataSet"/>.</returns>
        internal static List <Devotee> GetDevoteeDetailsByDate(DateTime periodFrom, DateTime periodTo)
        {
            List <Devotee> lstDevotee = new List <Devotee>();

            OpenSqlCeConnection();
            try
            {
                sqlQuery = "SELECT ReceiptNumber,DevoteeName,Address,Country,State,City,Amount,ReceiptCreatedDate,AnadhanamDate,ChequeNo,ChequeDate,ChequeDrawn,Mode,ContactNumber FROM  tblAnnadhanamDetails WHERE (AnadhanamDate>='" + periodFrom + "' AND  AnadhanamDate<='" + periodTo + "') Order By AnadhanamDate Asc";
                using (con)
                {
                    using (SqlCeDataAdapter da = new SqlCeDataAdapter())
                    {
                        SqlCeCommand cmd = new SqlCeCommand(sqlQuery, con)
                        {
                            Connection = con
                        };
                        da.SelectCommand = cmd;

                        DataSet ds = new DataSet();
                        da.Fill(ds);
                        con.Close();


                        if (ds.Tables[0].Rows.Count > 0)
                        {
                            foreach (DataRow dr in ds.Tables[0].Rows)
                            {
                                Devotee devotee = new Devotee();
                                if (dr != null)
                                {
                                    if (!string.IsNullOrWhiteSpace(Convert.ToString(dr.ItemArray[12])) && Convert.ToString(dr.ItemArray[12]).ToUpper() == "CHEQUE")
                                    {
                                        devotee.PaymentMode = PaymentMode.CHEQUE;
                                        devotee.ChequeNo    = Convert.ToString(dr.ItemArray[9]);
                                        devotee.ChequeDate  = Convert.ToDateTime(dr.ItemArray[10]);
                                        devotee.ChequeDrawn = Convert.ToString(dr.ItemArray[11]);
                                    }
                                    else
                                    {
                                        devotee.PaymentMode = PaymentMode.CASH;
                                    }
                                    devotee.ReceiptNumber      = Convert.ToInt32(dr.ItemArray[0]);
                                    devotee.DevoteeName        = Convert.ToString(dr.ItemArray[1]);
                                    devotee.Address            = Convert.ToString(dr.ItemArray[2]);
                                    devotee.Country            = Convert.ToString(dr.ItemArray[3]);
                                    devotee.State              = Convert.ToString(dr.ItemArray[4]);
                                    devotee.City               = Convert.ToString(dr.ItemArray[5]);
                                    devotee.Amount             = Convert.ToInt32(dr.ItemArray[6]);
                                    devotee.ReceiptCreatedDate = Convert.ToDateTime(dr.ItemArray[7]);
                                    devotee.AnadhanamDate      = Convert.ToDateTime(dr.ItemArray[8]);
                                    devotee.ContactNumber      = Convert.ToString(dr.ItemArray[13]);
                                }
                                lstDevotee.Add(devotee);
                            }
                        }
                    }
                }
            }
            catch (SqlCeException ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            return(lstDevotee);
        }
Esempio n. 14
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.UserName, Email = info.Principal.FindFirstValue(ClaimTypes.Email)
                };
                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);

                        // If account confirmation is required, we need to show the link if we don't have a real email sender
                        //if (_userManager.Options.SignIn.RequireConfirmedAccount)
                        //{
                        //    return RedirectToPage("./RegisterConfirmation", new { Email = Input.Email });
                        //}

                        //await _signInManager.SignInAsync(user, isPersistent: false);
                        //var userId = await _userManager.GetUserIdAsync(user);
                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        //var callbackUrl = Url.Page(
                        //    "/Account/ConfirmEmail",
                        //    pageHandler: null,
                        //    values: new { area = "Identity", userId = userId, code = code },
                        //    protocol: Request.Scheme);

                        //await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                        //    $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                        var result1 = await _userManager.ConfirmEmailAsync(user, code);

                        var devotee = new Devotee {
                            UserId = user.Id, FirstName = Input.FirstName, LastName = Input.LastName, RelationshipWithUser = Common.Relation.Self
                        };
                        _context.Devotees.Add(devotee);
                        await _context.SaveChangesAsync();

                        // Sign in the user with this external login provider if the user already has a login.
                        var result2 = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent : false, bypassTwoFactor : true);

                        if (result2.Succeeded)
                        {
                            _logger.LogInformation("{Name} logged in with {LoginProvider} provider.", info.Principal.Identity.Name, info.LoginProvider);
                            return(LocalRedirect(returnUrl));
                        }

                        return(Page());
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            LoginProvider = info.LoginProvider;
            ReturnUrl     = returnUrl;
            return(Page());
        }