private void sendmail(string subject) { string sender = (string)Application["sender_email"]; string server = (string)Application["sender_server"]; int owid3 = Int32.Parse(ownid.Text); carrentalEntities db = new carrentalEntities(); owner oo = db.owners.Where(x => x.oid == owid3).FirstOrDefault <owner>(); string emailid = oo.email; //Response.Write(emailid); MailMessage mail = new MailMessage(); mail.From = new MailAddress(sender); mail.To.Add(new MailAddress(emailid)); mail.Subject = subject; mail.Body = "Your Car Request has been accepted.Your Carno:" + carno.Text.ToString(); mail.Body += "Offered rentprice:" + rentprice.Text.ToString(); SmtpClient smtp = new SmtpClient(server, 587); smtp.EnableSsl = true; smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.Credentials = new System.Net.NetworkCredential(sender, "Qtnsqc16"); smtp.Send(mail); }
protected void add_Click1(object sender, EventArgs e) { one = sdate.Text; two = starttime.Text; three = edate.Text; four = endtime.Text; string mail = Session["loginid"].ToString(); owner oo = db.owners.Where(x => x.email == mail).FirstOrDefault <owner>(); string status = "pending"; cd.carno = carno.Text; cd.color = color.Text; cd.brand = brand.Text; cd.model = model.Text; cd.capacity = Int32.Parse(capacity.Text); cd.mileage = Double.Parse(mileage.Text); cd.requeststatus = status; cd.rentprice = Int32.Parse(rentp.Text); cd.startdate = Convert.ToDateTime(one + " " + two); cd.enddate = Convert.ToDateTime(three + " " + four); cd.requeststatus = status; cd.oid = oo.oid; postedfile = carimage.PostedFile; string str = Path.GetFileName(postedfile.FileName); Stream stream = postedfile.InputStream; BinaryReader br = new BinaryReader(stream); br.ReadBytes((int)stream.Length); cd.carimage = "~/Cars_pic/" + str; postedfile.SaveAs(Server.MapPath("~/Cars_pic/") + str); db.carrequests.Add(cd); try { int n = db.SaveChanges(); msg.Text = "Car request sent successfully"; msg.ForeColor = System.Drawing.Color.Green; } catch (Exception err) { msg.Text = "Some Error Occured"; msg.ForeColor = System.Drawing.Color.Red; } }
protected void add_Click(object sender, EventArgs e) { carrentalEntities db = new carrentalEntities(); string role = DropDownList1.SelectedItem.Text; customer c = new customer(); string fname = firstname.Text; string lname = lastname.Text; string mno = (mobileno.Text); string mail = email.Text; string license = licenceno.Text; string add = address.Text; if (DropDownList1.SelectedItem.Text == "Customer") { //Login l = new Login(); var already = from x in db.Logins where x.LoginId == email.Text && x.Role == role select x; int count = 0; foreach (var a in already) { count++; } if (count > 0) { msg.Text = "You Have Already Registered, Please Login!!"; msg.ForeColor = System.Drawing.Color.Red; return; } else { Login l = new Login(); l.Role = DropDownList1.SelectedItem.Text.ToString(); l.LoginId = email.Text.ToString(); l.Password = pwd.Text; c.email = email.Text; c.firstname = fname; c.lastname = lname; c.licenceno = license; c.address = add; c.mobileno = mno; db.customers.Add(c); db.Logins.Add(l); try { int n = db.SaveChanges(); sendmail("Successfully registered"); msg.Text = "Successfully registered"; msg.ForeColor = System.Drawing.Color.Green; } catch (Exception err) { msg.Text = "Some Error Occured"; msg.ForeColor = System.Drawing.Color.Red; } } } else if (DropDownList1.SelectedItem.Text == "Owner") { var already = from x in db.Logins where x.LoginId == email.Text && x.Role == role select x; int count = 0; foreach (var a in already) { count++; } if (count > 0) { msg.Text = "You Have Already Registered, Please Login!!"; msg.ForeColor = System.Drawing.Color.Red; } else { Login p = new Login(); owner o = new owner(); p.Role = DropDownList1.SelectedItem.Text.ToString(); p.LoginId = email.Text.ToString(); p.Password = pwd.Text; o.email = email.Text; o.firstname = fname; o.lastname = lname; o.address = add; o.phone = mno; db.owners.Add(o); db.Logins.Add(p); } try { int k = db.SaveChanges(); sendmail("Successfully registered"); msg.Text = "Successfully registered"; msg.ForeColor = System.Drawing.Color.Green; } catch (Exception err) { msg.Text = "Some Error Occured"; msg.ForeColor = System.Drawing.Color.Red; } } }