public ActionResult DeleteConfirmed(int id)
        {
            ContractorAcceptedBids contractorAcceptedBids = db.ContractorAcceptedBids.Find(id);

            db.ContractorAcceptedBids.Remove(contractorAcceptedBids);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public ActionResult Create([Bind(Include = "ID,ConUsername,HomeUsername,ConFirstName,HomeFirstname,ConLastName,HomeLastName,ConAddress,HomeAddress,ConCity,HomeCity,ConState,HomeState,ConZip,HomeZip,ConEmail,HomeEmail,PostedDate,Bid,CompletionDeadline,Description,Confirmed")] ContractorAcceptedBids contractorAcceptedBids)
        {
            if (ModelState.IsValid)
            {
                db.ContractorAcceptedBids.Add(contractorAcceptedBids);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(contractorAcceptedBids));
        }
        public ActionResult Edit([Bind(Include = "ID,ConUsername,HomeUsername,ConFirstName,HomeFirstname,ConLastName,HomeLastName,ConAddress,HomeAddress,ConCity,HomeCity,ConState,HomeState,ConZip,HomeZip,Conemail,Homeemail,PostedDate,Bid,CompletionDeadline,Description,confirmed,ServiceNumber")] ContractorAcceptedBids contractorAcceptedBids)

        //,HomeUsername,ConFirstName,HomeFirstname,ConLastName,HomeLastName,ConAddress,HomeAddress,ConCity,HomeCity,ConState,HomeState,ConZip,HomeZip,Conemail,Homeemail,PostedDate,Bid,CompletionDeadline,Description,confirmed")] ContractorAcceptedBids contractorAcceptedBids)
        {
            if (ModelState.IsValid)
            {
                db.Entry(contractorAcceptedBids).State = EntityState.Modified;
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }
            return(View(contractorAcceptedBids));
        }
        // GET: ContractorAcceptedBids/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ContractorAcceptedBids contractorAcceptedBids = db.ContractorAcceptedBids.Find(id);

            if (contractorAcceptedBids == null)
            {
                return(HttpNotFound());
            }
            return(View(contractorAcceptedBids));
        }
        // GET: ContractorAcceptedBids/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            ContractorAcceptedBids contractorAcceptedBids = db.ContractorAcceptedBids.Find(id);
            ContractorAcceptedBids Pics = db.ContractorAcceptedBids.Include(i => i.ServiceRequestPaths).SingleOrDefault(i => i.ID == id);

            if (contractorAcceptedBids == null)
            {
                return(HttpNotFound());
            }
            return(View(contractorAcceptedBids));
        }
        public ActionResult HomeownerConfirmation(int?id)
        {
            string identity = System.Web.HttpContext.Current.User.Identity.GetUserId();

            if (identity == null)
            {
                return(RedirectToAction("Unauthorized_Access", "Home"));
            }
            var    acceptList      = db.ContractorAcceptedBids.ToList();
            string HomeOwnerEmail1 = "";
            string HomeOwnerEmail2 = "";
            var    person          = db.Homeowners.Where(x => x.UserId == identity).SingleOrDefault();

            foreach (var user in db.Users)
            {
                if (user.Id == identity)
                {
                    HomeOwnerEmail2 = user.Email;
                }
            }

            foreach (var i in acceptList)
            {
                if (id == i.ID)
                {
                    HomeOwnerEmail1 = i.HomeEmail;
                }
            }

            if (this.User.IsInRole("Admin") || HomeOwnerEmail1 == HomeOwnerEmail2)
            {
                if (id == null)
                {
                    return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
                }
                ContractorAcceptedBids contractorAcceptedBids = db.ContractorAcceptedBids.Find(id);
                if (contractorAcceptedBids == null)
                {
                    return(HttpNotFound());
                }
                return(View(contractorAcceptedBids));
            }
            else
            {
                return(RedirectToAction("Unauthorized_Access", "Home"));
            }
        }
        public ActionResult acceptanceConfirmation(int id)
        {
            //if (this.User.IsInRole"conr"){

            //}
            //}
            string ConEmail     = "";
            string ConUserName  = "";
            string ConFirstName = "";
            string ConLastName  = "";
            string ConAddress   = "";
            string ConCity      = "";
            string ConState     = "";
            string ConZip       = "";
            int    Invoice      = 1;

            var    myMessage       = new SendGrid.SendGridMessage();
            string name            = System.IO.File.ReadAllText(@"C:\Users\erick\Desktop\Credentials\name.txt");
            string pass            = System.IO.File.ReadAllText(@"C:\Users\erick\Desktop\Credentials\password.txt");
            var    contractors     = db.Contractors.ToList();
            var    servicerequests = db.ServiceRequests.ToList();
            var    acceptList      = db.ContractorAcceptedBids.ToList();
            string identity        = System.Web.HttpContext.Current.User.Identity.GetUserId();
            var    person          = db.Contractors.Where(x => x.UserId == identity).SingleOrDefault();

            foreach (var user in db.Users)
            {
                if (user.Id == identity)
                {
                    ConEmail = user.Email;
                    //username1 = user.UserName;
                    foreach (var con in contractors)
                    {
                        if (con.email == ConEmail)
                        {
                            ConUserName  = con.Username;
                            ConFirstName = con.FirstName;
                            ConLastName  = con.LastName;
                            ConAddress   = con.Address;
                            ConCity      = con.City;
                            ConState     = con.State;
                            ConZip       = con.Zip;
                        }
                    }
                }
            }



            foreach (var i in servicerequests)
            {
                if (id == i.ID)
                {
                    if (i.expired == true)
                    {
                        return(RedirectToAction("expired", "ServiceRequests"));
                    }

                    if (i.Confirmed == true)
                    {
                        return(RedirectToAction("Already_Confirmed", "ContractorAcceptedBids"));
                    }

                    ContractorAcceptedBids bid = new ContractorAcceptedBids();
                    bid.ServiceRequestPaths = new List <ServiceRequestPath>();
                    bid.ConUsername         = ConUserName;
                    bid.HomeUsername        = i.Username;
                    bid.ConFirstName        = ConFirstName;
                    bid.HomeFirstname       = i.FirstName;
                    bid.ConLastName         = ConLastName;
                    bid.HomeLastName        = i.LastName;
                    bid.ConAddress          = ConAddress;
                    bid.HomeAddress         = i.Address;
                    bid.ConCity             = ConCity;
                    bid.HomeCity            = i.City;
                    bid.ConState            = ConState;
                    bid.HomeState           = i.State;
                    bid.ConZip             = ConZip;
                    bid.HomeZip            = i.Zip;
                    bid.ConEmail           = ConEmail;
                    bid.HomeEmail          = i.email;
                    bid.PostedDate         = i.PostedDate;
                    bid.CompletionDeadline = i.CompletionDeadline;
                    bid.Description        = i.Description;
                    bid.Bid           = i.Bid;
                    bid.ServiceNumber = i.ServiceNumber;
                    bid.Files         = i.Files;
                    foreach (var x in acceptList)
                    {
                        if ((x.ConUsername == bid.ConUsername) && (x.ServiceNumber == bid.ServiceNumber))
                        {
                            return(RedirectToAction("Duplicate", "ContractorAcceptedBids"));
                        }
                    }
                    foreach (var x in i.ServiceRequestPaths)
                    {
                        bid.ServiceRequestPaths.Add(new ServiceRequestPath()
                        {
                            FileName = x.FileName
                        });
                    }
                    bid.expired   = i.expired;
                    bid.Confirmed = i.Confirmed;
                    //bid.ServiceNumber = i.ServiceNumber;
                    //foreach(var x in acceptList)
                    //{
                    //    if((x.ConUsername == bid.ConUsername) && (x.ServiceNumber == bid.ServiceNumber))
                    //        {
                    //        return RedirectToAction("Duplicate", "ContractorAcceptedBids");
                    //        }
                    //}
                    db.ContractorAcceptedBids.Add(bid);
                    db.SaveChanges();
                    Invoice = bid.ID;
                    myMessage.AddTo(i.email);
                    myMessage.From    = new MailAddress("*****@*****.**", "Admin");
                    myMessage.Subject = "Service Request Acceptance!!";
                    string url = "http://localhost:14703/ContractorAcceptedBids/HomeownerConfirmation/" + Invoice;
                    //string message = "Job Location: <br>" + i.Address + "<br>" + i.City + "<br>" + i.State + "<br>" + i.Zip + "<br>" + "<br>" + "Job Description: <br>" + i.Description + "<br>" + "<br>" + "Bid price: <br>$" + i.Bid + "<br>" + "<br>" + "Must be completed by: <br>" + i.CompletionDeadline + "<br>" + "<br>" + "Date Posted: <br>" + i.PostedDate + "<br>" + "<br>" + "To accept job, click on link below: <br><a href =" + url + "> Click Here </a>";
                    String message = "Hello " + i.FirstName + "," + "<br>" + "<br>" + "Contractor " + ConUserName + " has offered to perform your following service request:" + "<br>" + "<br>" + i.Description + "<br>" + "<br>" + "To confirm acceptance, click on link below: <br><a href =" + url + "> Click Here </a>";
                    myMessage.Html = message;
                    var credentials  = new NetworkCredential(name, pass);
                    var transportWeb = new SendGrid.Web(credentials);
                    transportWeb.DeliverAsync(myMessage);
                    conList.Add(ConEmail + i.ID);
                }
                //i.posted = true;
                db.SaveChanges();
            }

            return(RedirectToAction("About", "Home"));
        }