protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                using (SalesDBEntities1 objEntity = new SalesDBEntities1())
                {
                    userDetail objpro = objEntity.userDetails.FirstOrDefault(Pro => Pro.userName == txtUserName.Text);
                    if (objpro != null)
                    {
                        liVal.Text = "User Name Already Exists. <br/> Please Enter different Name.";
                        return;
                    }
                    else
                    {
                        userDetail objProNew = new userDetail();
                        if (ddlAccount.SelectedValue != "0")
                        {
                            objProNew.accountID = Convert.ToDecimal(ddlAccount.SelectedValue);
                        }
                        if (ddlStore.SelectedValue != "0")
                        {
                            objProNew.storeID = Convert.ToDecimal(ddlStore.SelectedValue);
                        }
                        if (ddlUserType.SelectedValue != "0")
                        {
                            objProNew.userGroupID = Convert.ToDecimal(ddlUserType.SelectedValue);
                        }
                        objProNew.state         = txtState.Text;
                        objProNew.isActive      = true;
                        objProNew.CreatedDate   = DateTime.Now;
                        objProNew.addressLine1  = txtAddLine1.Text;
                        objProNew.addressLine2  = txtAddressLine2.Text;
                        objProNew.city          = txtCity.Text;
                        objProNew.firstName     = txtFName.Text;
                        objProNew.lastName      = txtLName.Text;
                        objProNew.CreatedBy     = Convert.ToDecimal(Session["userID"]);
                        objProNew.contactNumber = txtContact.Text;
                        objProNew.userName      = txtUserName.Text;
                        objProNew.userPass      = StringCipher.EncryptStringAES(txtPass.Text);
                        objProNew.DOB           = Convert.ToDateTime(txtDOB.Text);
                        objEntity.userDetails.Add(objProNew);
                        objEntity.SaveChanges();

                        string filename = objProNew.userID.ToString() + ".jpg";
                        flPhoto.SaveAs(Server.MapPath("~/userData/userPic/" + filename));


                        Response.Redirect("~/adUsers.aspx", false);
                    }
                }
            }
            catch (Exception ex)
            {
                appOperations.LogException(ex, "User Save");
                liVal.Text = ex.Message;
            }
        }
Пример #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                decimal userID = Convert.ToDecimal(Session["userID"]);
                using (SalesDBEntities1 objEntity = new SalesDBEntities1())
                {
                    userDetail objProNew = objEntity.userDetails.FirstOrDefault(Pro => Pro.userID == userID);
                    if (objProNew != null)
                    {
                        objProNew.state = txtState.Text;

                        objProNew.addressLine1 = txtAddLine1.Text;
                        objProNew.addressLine2 = txtAddressLine2.Text;
                        objProNew.city         = txtCity.Text;
                        objProNew.firstName    = txtFName.Text;
                        objProNew.lastName     = txtLName.Text;

                        objProNew.contactNumber = txtContact.Text;
                        objProNew.userPass      = StringCipher.EncryptStringAES(txtPass.Text);
                        objProNew.DOB           = Convert.ToDateTime(txtDOB.Text);

                        objEntity.SaveChanges();

                        string filename = objProNew.userID.ToString() + ".jpg";
                        flPhoto.SaveAs(Server.MapPath("~/userData/userPic/" + filename));


                        Response.Redirect("~/adUsers.aspx", false);
                    }
                }
            }
            catch (Exception ex)
            {
                appOperations.LogException(ex, "User Save");
                liVal.Text = ex.Message;
            }
        }