Example #1
0
        public ActionResult DeleteContact(int id)
        {
            bool   status  = false;
            string message = "";

            using (DBASPEntities dc = new DBASPEntities())
            {
                var v = dc.Contacts.Where(a => a.ContactID.Equals(id)).FirstOrDefault();
                if (v != null)
                {
                    dc.Contacts.Remove(v);
                    dc.SaveChanges();
                    status  = true;
                    message = "Successfully Deleted!";
                }
                else
                {
                    return(HttpNotFound());
                }
            }

            return(new JsonResult {
                Data = new { status = status, message = message }
            });
        }
Example #2
0
        public JsonResult GetContacts()
        {
            List <Contact> all = null;

            using (DBASPEntities dc = new DBASPEntities())
            {
                var contacts = (from a in dc.Contacts
                                join b in dc.Countries on a.CountryID equals b.CountryID
                                join c in dc.States on a.StateID equals c.StateID
                                select new
                {
                    a,
                    b.CountryName,
                    c.StateName
                });
                if (contacts != null)
                {
                    all = new List <Contact>();
                    foreach (var i in contacts)
                    {
                        Contact con = i.a;
                        con.CountryName = i.CountryName;
                        con.StateName   = i.StateName;
                        all.Add(con);
                    }
                }
            }

            return(new JsonResult {
                Data = all, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #3
0
        public Contact GetContact(int contactID)
        {
            Contact contact = null;

            using (DBASPEntities dc = new DBASPEntities())
            {
                var v = (from a in dc.Contacts
                         join b in dc.Countries on a.CountryID equals b.CountryID
                         join c in dc.States on a.StateID equals c.StateID
                         select new
                {
                    a,
                    b.CountryName,
                    c.StateName
                }).FirstOrDefault();

                if (v != null)
                {
                    contact             = v.a;
                    contact.CountryName = v.CountryName;
                    contact.StateName   = v.StateName;
                }

                return(contact);
            }
        }
Example #4
0
 public List <State> GetState(int countryID)
 {
     using (DBASPEntities dc = new DBASPEntities())
     {
         return(dc.States.Where(a => a.CountryID == countryID).OrderBy(a => a.StateName).ToList());
     }
 }
Example #5
0
 public List <Country> GetCountry()
 {
     using (DBASPEntities dc = new DBASPEntities())
     {
         return(dc.Countries.OrderBy(a => a.CountryName).ToList());
     }
 }
Example #6
0
 public JsonResult GetStateList(int countryID)
 {
     using (DBASPEntities dc = new DBASPEntities())
     {
         return(new JsonResult {
             Data = GetState(countryID), JsonRequestBehavior = JsonRequestBehavior.AllowGet
         });
     }
 }
Example #7
0
        public ActionResult Save(Contact c)
        {
            string message = "";
            bool   status  = false;

            if (ModelState.IsValid)
            {
                using (DBASPEntities dc = new DBASPEntities())
                {
                    if (c.ContactID > 0)
                    {
                        var v = dc.Contacts.Where(a => a.ContactID.Equals(c.ContactID)).FirstOrDefault();
                        if (v != null)
                        {
                            v.ContactPerson = c.ContactPerson;
                            v.ContactNo     = c.ContactNo;
                            v.CountryID     = c.CountryID;
                            v.StateID       = c.StateID;
                        }
                        else
                        {
                            return(HttpNotFound());
                        }
                    }
                    else
                    {
                        dc.Contacts.Add(c);
                    }

                    dc.SaveChanges();
                    status  = true;
                    message = "Successfully Saved.";
                }
            }
            else
            {
                message = "Error! Please try again.";
            }


            return(new JsonResult {
                Data = new { status = status, message = message }
            });
        }