Exemplo n.º 1
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            ContactUsRepository repContact = new ContactUsRepository();
            AdminsRepository    ad         = new AdminsRepository();

            DataAccess.Admin addsd = ad.getAdmin(Session["adminid"].ToString().ToInt());
            if (tbxPass.Text != "")
            {
                addsd.Password = tbxPass.Text;
                ad.SaveAdmin(addsd);
            }
            ContactWay cnw = repContact.Findcwy(1);

            if (tbxAbout.Text != "")
            {
                cnw.AboutUs = tbxAbout.Text;
            }
            if (tbxAdress.Text != "")
            {
                cnw.Adrees = tbxAdress.Text;
            }
            if (tbxMail.Text != "")
            {
                cnw.Email = tbxMail.Text;
            }
            if (tbxPhone.Text != "")
            {
                cnw.PhoneNumber = tbxPhone.Text;
            }
            if (tbxAboutPage.Text != "")
            {
                cnw.AboutPage = tbxAboutPage.Text;
            }
            if (tbxtele.Text != "")
            {
                cnw.Telegram = tbxtele.Text;
            }
            if (tbxInsta.Text != "")
            {
                cnw.Instagram = tbxInsta.Text;
            }
            if (FileUpload1.HasFile)
            {
                string filename = Path.GetFileName(FileUpload1.FileName);
                string rand     = DBManager.CurrentTimeWithoutColons() + DBManager.CurrentPersianDateWithoutSlash();
                filename = rand + filename;
                string ps = Server.MapPath(@"~\img\") + filename;
                FileUpload1.SaveAs(ps);
                FileStream fStream  = File.OpenRead(ps);
                byte[]     contents = new byte[fStream.Length];
                fStream.Read(contents, 0, (int)fStream.Length);
                fStream.Close();
                //FileInfo fi = new FileInfo(Server.MapPath(@"~\img\") + cnw.logo.Substring(5));
                //fi.Delete();
                //FileInfo fil = new FileInfo(Server.MapPath(@"~\img\") + cnw.logo.Substring(5));
                //fil.Delete();
                cnw.logo = "/img/" + filename;
            }

            if (repContact.Savecwy(cnw))
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' ثبت با موفقیت انجام شد  ');", true);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' ثبت با خطا مواجه شد ! ');", true);
            }
        }