Example #1
0
        protected void btnSubmit_Click1(object sender, EventArgs e)
        {
            try
            {
                var ddlselectedvalue = ddlUserList.SelectedItem.Value;
                StringCollection sc  = new StringCollection();

                foreach (int i in lbBuisnessType.GetSelectedIndices())
                {
                    GST_MST_USER_BUSINESSTYPE bsnstype = new GST_MST_USER_BUSINESSTYPE();
                    bsnstype.BusinessID = Convert.ToInt32(lbBuisnessType.Items[i].Value);
                    bsnstype.UserID     = ddlselectedvalue;
                    //var abc = unitOfwork.AspnetRepository.Filter(s => s.Id == a).Select(s => new { Id = s.Id });
                    bsnstype.CreatedBy   = Common.LoggedInUserID();
                    bsnstype.CreatedDate = DateTime.Now;
                    unitOfwork.UserBuisnessTypeRepository.Create(bsnstype);
                    unitOfwork.Save();
                    uc_sucess.SuccessMessage = "Data Save Successfully.";
                    //  uc_sucess.Visible = !String.IsNullOrEmpty(SuccessMessage);
                }
            }
            catch (Exception ex)
            {
                cls_ErrorLog ob = new cls_ErrorLog();
                cls_ErrorLog.LogError(ex, Common.LoggedInUserID());
            }
        }
Example #2
0
        protected void btnCreateUsers_Click(object sender, EventArgs e)
        {
            try
            {
                Byte[] ImgByte = null;
                if (FiSmallImage.HasFile)
                {
                    ImgByte = Common.GetImageByte(FiSmallImage);
                    decimal size = Math.Round(((decimal)FiSmallImage.PostedFile.ContentLength / (decimal)1024), 2);
                    if (size > 2048)
                    {
                        uc_sucess.ErrorMessage = "Size of the image to be uploaded cannot exceed two mb.";
                        return;
                    }
                }
                // ApplicationUserManager userManager = new ApplicationUserManager(new UserStore<ApplicationUser>(_db));
                var isPersistData = UserManager.Users.Where(u => u.Email.Contains(txtEmailID.Text.Trim()) || u.GSTNNo.Contains(txtGSTNNumber.Text.Trim()));
                if (isPersistData != null)
                {
                    var user = new ApplicationUser()
                    {
                        SmallImage  = ImgByte,
                        UserName    = txtUserName.Text.Replace(" ", ""),
                        Email       = txtEmailID.Text.Replace(" ", ""),
                        FirstName   = txtFirstName.Text.Trim(),
                        LastName    = txtLastName.Text.Trim(),
                        GSTNNo      = txtGSTNNumber.Text.Replace(" ", ""),
                        GSTINUserId = txtGstUser.Text.Trim(),
                        //OrganizationName = txtOrganization.Text.Trim(),
                        PhoneNumber     = txtPhoneNumber.Text.Trim(),
                        StateCode       = ddlStateCode.SelectedItem.Value,
                        NameOfSignatory = txtnamesignatory.Text.Trim(),
                        Designation     = Convert.ToString(ddlDesig.SelectedIndex),
                        GrossTurnOver   = Convert.ToDecimal(txt_Grossturnover.Text.Trim()),
                        Address         = txtCreateAdd.Text.Trim(),
                        ITC             = Convert.ToDecimal(txt_ITC.Text.Trim()),
                        UserType        = (byte)(EnumConstants.UserType)Enum.Parse(typeof(EnumConstants.UserType), ddluser_type.SelectedItem.Value),
                        RegisterWithUs  = Convert.ToBoolean((EnumConstants.RegisteredWithUs)Enum.Parse(typeof(EnumConstants.RegisteredWithUs), ddlRegistered.SelectedItem.Value)),
                        ParentUserID    = UserManager.IsInRole(HttpContext.Current.User.Identity.GetUserId(), EnumConstants.RoleName.Admin.ToString()) ? HttpContext.Current.User.Identity.GetUserId() : string.Empty
                    };

                    string test        = txtOrganizationName.Text;
                    var    getitemcode = unitOfwork.AspnetRepository.Find(c => c.OrganizationName == test);
                    if (getitemcode == null)
                    {
                        user.OrganizationName = txtOrganizationName.Text;

                        //if (ddlRolesList.SelectedIndex > -1)
                        //{
                        IdentityResult result = UserManager.Create(user, txtPassword.Text.Trim());
                        // IdentityResult result = manager.Create(user, txtPassword.Text.Trim());

                        if (result.Succeeded)
                        {
                            if (ddlRolesList.SelectedIndex > -1)
                            {
                                UserManager.AddToRole(user.Id, ddlRolesList.SelectedItem.Text);
                            }
                            foreach (int i in lbBuisnessType.GetSelectedIndices())
                            {
                                GST_MST_USER_BUSINESSTYPE ob = new GST_MST_USER_BUSINESSTYPE();
                                ob.BusinessID  = Convert.ToInt32(lbBuisnessType.Items[i].Value);
                                ob.UserID      = user.Id;
                                ob.CreatedBy   = Common.LoggedInUserID();
                                ob.CreatedDate = DateTime.Now;
                                unitOfwork.UserBuisnessTypeRepository.Create(ob);
                                unitOfwork.Save();
                            }
                            //var code = UserManager.GenerateEmailConfirmationToken(user.Id);
                            //userManager.EmailService();
                            //var callbackUrl = Url.Action("ConfirmEmail", "Account",new { userId = user.Id, code = code },protocol: Request.Url.Scheme);
                            ClearField();
                            // BindUsers();
                            uc_sucess.SuccessMessage = "User Created Successfully.";
                            uc_sucess.Visible        = !String.IsNullOrEmpty(SuccessMessage);
                        }

                        else
                        {
                            uc_sucess.SuccessMessage = result.Errors.FirstOrDefault();// "Unable to create or username already exist.";//result.Errors.Where(e=>e.);//
                            uc_sucess.Visible        = !String.IsNullOrEmpty(SuccessMessage);
                        }
                    }
                    else
                    {
                        uc_sucess.ErrorMessage = "Organization Name Already Exist!";
                        uc_sucess.Visible      = true;
                    }
                    //}
                    //else
                    //{
                    //    uc_sucess.SuccessMessage = "Kindly select role from role  list.";
                    //    uc_sucess.Visible = !String.IsNullOrEmpty(SuccessMessage);
                    //}
                }
                else
                {
                    uc_sucess.SuccessMessage = "Alert! Email-Id or GSTIN is already exists.";
                    uc_sucess.Visible        = !String.IsNullOrEmpty(uc_sucess.SuccessMessage);
                }
            }
            catch (DbEntityValidationException ex)
            {
                cls_ErrorLog ob = new cls_ErrorLog();
                cls_ErrorLog.LogError(ex, Common.LoggedInUserID());
                //foreach (var eve in ex.EntityValidationErrors)
                //{
                //    Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                //        eve.Entry.Entity.GetType().Name, eve.Entry.State);
                //    foreach (var ve in eve.ValidationErrors)
                //    {
                //        Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                //            ve.PropertyName, ve.ErrorMessage);
                //    }
                //}
                // uc_sucess.ErrorMessage = ex.Message;
                // uc_sucess.VisibleError = true;
            }
        }