Ejemplo n.º 1
0
        public ActionResult Create(PersonDirectoryModel model, HttpPostedFileBase Image1)
        {
            List <Country> allCountry = new List <Country>();
            List <City>    allCity    = new List <City>();

            allCountry = db.Countries.OrderBy(a => a.CountryName).ToList();

            if (model != null && model.ClientCountryId != 0)
            {
                allCity = db.Cities.Where(a => a.CountryId == model.ClientCountryId).OrderBy(a => a.CityName).ToList();
            }

            ViewBag.CountryId = new SelectList(allCountry, "CountryId", "CountryName", model.ClientCountryId);
            ViewBag.CityId    = new SelectList(allCity, "CityId", "CityName", model.ClientCityId);

            try
            {
                if (Image1 != null)
                {
                    model.ProfilePic = new byte[Image1.ContentLength];
                    Image1.InputStream.Read(model.ProfilePic, 0, Image1.ContentLength);
                }
                db.PersonDirectoryModel.Add(model);
                db.SaveChanges();
                ModelState.Clear();
                model           = null;
                ViewBag.Message = "Successfully Submited";
                return(View(model));
            }
            catch
            {
                ViewBag.Message = "UnSuccessful";
                return(View());
            }
        }
Ejemplo n.º 2
0
        // GET: PeopleDirectory/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            PersonDirectoryModel people = db.PersonDirectoryModel.Find(id);

            if (people == null)
            {
                return(HttpNotFound());
            }
            else
            {
                db.PersonDirectoryModel.Remove(people);
                db.SaveChanges();
            }
            return(RedirectToAction("Index", "PeopleDirectory"));
        }
Ejemplo n.º 3
0
        // GET: PeopleDirectory/Edit/
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            List <Country> allCountry = new List <Country>();
            List <City>    allCity    = new List <City>();

            allCountry = db.Countries.OrderBy(a => a.CountryName).ToList();
            allCity    = db.Cities.OrderBy(a => a.CityName).ToList();

            ViewBag.CountryId = new SelectList(allCountry, "CountryId", "CountryName");
            ViewBag.CityId    = new SelectList(allCity, "CityId", "CityName");

            PersonDirectoryModel people = db.PersonDirectoryModel.Find(id);

            if (people == null)
            {
                return(HttpNotFound());
            }
            return(View(people));
        }
Ejemplo n.º 4
0
        public async Task <ActionResult> Edit(int?id, PersonDirectoryModel model, HttpPostedFileBase Image1)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            PersonDirectoryModel people = db.PersonDirectoryModel.Find(id);

            List <Country> allCountry = new List <Country>();
            List <City>    allCity    = new List <City>();

            allCountry = db.Countries.OrderBy(a => a.CountryName).ToList();
            allCity    = db.Cities.OrderBy(a => a.CityName).ToList();

            ViewBag.CountryId = new SelectList(allCountry, "CountryId", "CountryName");
            ViewBag.CityId    = new SelectList(allCity, "CityId", "CityName");


            if (ModelState.IsValid)
            {
                try
                {
                    City    Citydata         = db.Cities.Find(people.ClientCityId);
                    Country Countrydata      = db.Countries.Find(people.ClientCountryId);
                    City    CitydataModel    = db.Cities.Find(model.ClientCityId);
                    Country CountrydataModel = db.Countries.Find(model.ClientCountryId);


                    var body = "<p>The Below Person Was Editied: </p>" +
                               "<p><b>Old Person:</b> <br>" +
                               "Name: {0} <br>" +
                               "SurName: {1} <br>" +
                               "Mobile Number: {2} <br>" +
                               "Gender: {3} <br>" +
                               "Email Address: {4} <br>" +
                               "Country: {5} <br>" +
                               "City: {6} <br></p>" +

                               "<p><b>New Person:</b>  <br>" +
                               "Name: {7} <br>" +
                               "SurName: {8} <br>" +
                               "Mobile Number: {9} <br>" +
                               "Gender: {10} <br>" +
                               "Email Address: {11} <br>" +
                               "Country: {12} <br>" +
                               "City: {13} </p>"
                    ;

                    var message = new MailMessage();
                    message.To.Add(new MailAddress("*****@*****.**"));  // replace with valid value [email protected]
                    message.From       = new MailAddress("*****@*****.**");
                    message.Subject    = "People Directory Update";
                    message.Body       = string.Format(body, people.Name, people.SurName, people.MobileNo, people.Gender, people.EmailAddress, Countrydata.CountryName, Citydata.CityName, model.Name, model.SurName, model.MobileNo, model.Gender, model.EmailAddress, CountrydataModel.CountryName, CitydataModel.CityName);
                    message.IsBodyHtml = true;

                    if (people.ProfilePic != null)
                    {
                        model.ProfilePic = people.ProfilePic;
                        string Filename = "";
                        if (Image1 != null)
                        {
                            Filename = "Old ";
                        }
                        message.Attachments.Add(new Attachment(new MemoryStream(people.ProfilePic), Filename + "Profile Picture.jpg"));
                    }

                    if (Image1 != null)
                    {
                        if (people.ProfilePic != null)
                        {
                            message.Attachments.Add(new Attachment(new MemoryStream(people.ProfilePic), "Old Profile Picture.jpg"));
                        }
                        people.ProfilePic = new byte[Image1.ContentLength];
                        Image1.InputStream.Read(people.ProfilePic, 0, Image1.ContentLength);
                        message.Attachments.Add(new Attachment(new MemoryStream(people.ProfilePic), "New Profile Picture" + Image1.FileName));
                    }
                    else
                    {
                        model.ProfilePic = people.ProfilePic;
                    }

                    people.Name         = model.Name;
                    people.SurName      = model.SurName;
                    people.MobileNo     = model.MobileNo;
                    people.Gender       = model.Gender;
                    people.EmailAddress = model.EmailAddress;

                    db.SaveChanges();
                    ModelState.Clear();
                    model = null;

                    using (var smtp = new SmtpClient())
                    {
                        smtp.UseDefaultCredentials = false;

                        smtp.Credentials = new System.Net.NetworkCredential("*****@*****.**", "666666n@lyD");
                        smtp.Host        = "smtp.gmail.com";
                        smtp.Port        = 587;
                        smtp.EnableSsl   = true;
                        await smtp.SendMailAsync(message);
                    }

                    ViewBag.Message = "Successfully Submited";
                    return(RedirectToAction("Index", "PeopleDirectory"));
                }
                catch (Exception e)
                {
                    model.ProfilePic = people.ProfilePic;
                    var error = e.Message;
                    ViewBag.Message = "UnSuccessful";
                    return(View());
                }
            }
            else
            {
                model.ProfilePic = people.ProfilePic;
                return(View(model));
            }
        }
Ejemplo n.º 5
0
        public ActionResult AddImage(PersonDirectoryModel model)
        {
            PersonDirectoryModel Pd = new PersonDirectoryModel();

            return(View(Pd));
        }