Link to home
Start Free TrialLog in
Avatar of Ann K
Ann K

asked on

Syntax Error

Can you tell me where exactly this error is?  I am using VS 2010 in windows 7 environment.
User generated imageUser generated image
//------------------------------------------------------------------------------
// <auto-generated>
//    This code was generated from a template.
//
//    Manual changes to this file may cause unexpected behavior in your application.
//    Manual changes to this file will be overwritten if the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Data.EntityClient;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;

[assembly: EdmSchemaAttribute()]
namespace AngularCRUD
{
    #region Contexts
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    public partial class MyDatabaseEntities : ObjectContext
    {
        #region Constructors
    
        /// <summary>
        /// Initializes a new MyDatabaseEntities object using the connection string found in the 'MyDatabaseEntities' section of the application configuration file.
        /// </summary>
        public MyDatabaseEntities() : base("name=MyDatabaseEntities", "MyDatabaseEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        /// <summary>
        /// Initialize a new MyDatabaseEntities object.
        /// </summary>
        public MyDatabaseEntities(string connectionString) : base(connectionString, "MyDatabaseEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        /// <summary>
        /// Initialize a new MyDatabaseEntities object.
        /// </summary>
        public MyDatabaseEntities(EntityConnection connection) : base(connection, "MyDatabaseEntities")
        {
            this.ContextOptions.LazyLoadingEnabled = true;
            OnContextCreated();
        }
    
        #endregion
    
        #region Partial Methods
    
        partial void OnContextCreated();
    
        #endregion
    
        #region ObjectSet Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        public ObjectSet<Contact> Contacts
        {
            get
            {
                if ((_Contacts == null))
                {
                    _Contacts = base.CreateObjectSet<Contact>("Contacts");
                }
                return _Contacts;
            }
        }
        private ObjectSet<Contact> _Contacts;

        #endregion

        #region AddTo Methods
    
        /// <summary>
        /// Deprecated Method for adding a new object to the Contacts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
        /// </summary>
        public void AddToContacts(Contact contact)
        {
            base.AddObject("Contacts", contact);
        }

        #endregion

    }

    #endregion

    #region Entities
    
    /// <summary>
    /// No Metadata Documentation available.
    /// </summary>
    [EdmEntityTypeAttribute(NamespaceName="MyDatabaseModel", Name="Contact")]
    [Serializable()]
    [DataContractAttribute(IsReference=true)]
    public partial class Contact : EntityObject
    {
        #region Factory Method
    
        /// <summary>
        /// Create a new Contact object.
        /// </summary>
        /// <param name="contactID">Initial value of the ContactID property.</param>
        /// <param name="contactName">Initial value of the ContactName property.</param>
        /// <param name="contactNo">Initial value of the ContactNo property.</param>
        public static Contact CreateContact(global::System.Int32 contactID, global::System.String contactName, global::System.String contactNo)
        {
            Contact contact = new Contact();
            contact.ContactID = contactID;
            contact.ContactName = contactName;
            contact.ContactNo = contactNo;
            return contact;
        }

        #endregion

        #region Primitive Properties
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=true, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.Int32 ContactID
        {
            get
            {
                return _ContactID;
            }
            set
            {
                if (_ContactID != value)
                {
                    OnContactIDChanging(value);
                    ReportPropertyChanging("ContactID");
                    _ContactID = StructuralObject.SetValidValue(value);
                    ReportPropertyChanged("ContactID");
                    OnContactIDChanged();
                }
            }
        }
        private global::System.Int32 _ContactID;
        partial void OnContactIDChanging(global::System.Int32 value);
        partial void OnContactIDChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String ContactName
        {
            get
            {
                return _ContactName;
            }
            set
            {
                OnContactNameChanging(value);
                ReportPropertyChanging("ContactName");
                _ContactName = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("ContactName");
                OnContactNameChanged();
            }
        }
        private global::System.String _ContactName;
        partial void OnContactNameChanging(global::System.String value);
        partial void OnContactNameChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=false)]
        [DataMemberAttribute()]
        public global::System.String ContactNo
        {
            get
            {
                return _ContactNo;
            }
            set
            {
                OnContactNoChanging(value);
                ReportPropertyChanging("ContactNo");
                _ContactNo = StructuralObject.SetValidValue(value, false);
                ReportPropertyChanged("ContactNo");
                OnContactNoChanged();
            }
        }
        private global::System.String _ContactNo;
        partial void OnContactNoChanging(global::System.String value);
        partial void OnContactNoChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String EmailID
        {
            get
            {
                return _EmailID;
            }
            set
            {
                OnEmailIDChanging(value);
                ReportPropertyChanging("EmailID");
                _EmailID = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("EmailID");
                OnEmailIDChanged();
            }
        }
        private global::System.String _EmailID;
        partial void OnEmailIDChanging(global::System.String value);
        partial void OnEmailIDChanged();
    
        /// <summary>
        /// No Metadata Documentation available.
        /// </summary>
        [EdmScalarPropertyAttribute(EntityKeyProperty=false, IsNullable=true)]
        [DataMemberAttribute()]
        public global::System.String Address
        {
            get
            {
                return _Address;
            }
            set
            {
                OnAddressChanging(value);
                ReportPropertyChanging("Address");
                _Address = StructuralObject.SetValidValue(value, true);
                ReportPropertyChanged("Address");
                OnAddressChanged();
            }
        }
        private global::System.String _Address;
        partial void OnAddressChanging(global::System.String value);
        partial void OnAddressChanged();

        #endregion

    
    }

    #endregion

    
}

Open in new window


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace AngularCRUD.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }


        public JsonResult GetContacts()
        {
            List<Contact> contactList = new List<Contact>();
            using (MyDatabaseEntities dc = new MyDatabaseEntities())
            {
                contactList = dc.Contacts.OrderBy(a => a.ContactName).ToList();
            }
            return new JsonResult { Data = contactList, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }

        //fetch contact by id
        public JsonResult GetContact(int contactID)
        {
            Contact contact = null;
            using (MyDatabaseEntities dc = new MyDatabaseEntities())
            {
                contact = dc.Contacts.Where(a => a.ContactID.Equals(contactID)).FirstOrDefault();
            }
            return new JsonResult { Data = contact, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
        }

        // save contact
        [HttpPost]
        public JsonResult SaveContact(Contact contact)
        {
            bool status = false;
            string message = "";
            try
            {
                if (ModelState.IsValid)
                {
                    using (MyDatabaseEntities dc = new MyDatabaseEntities())
                    {
                        if (contact.ContactID > 0)
                        {
                            //Update
                            var c = dc.Contacts.Where(a => a.ContactID.Equals(contact.ContactID)).FirstOrDefault();
                            if (c != null)
                            {
                                c.ContactName = contact.ContactName;
                                c.ContactNo = contact.ContactNo;
                                c.EmailID = contact.EmailID;
                                c.Address = contact.Address;
                            }
                        }
                        else
                        {
                            //create
                            dc.Contacts.Add(contact);
                        }
                        dc.SaveChanges();
                        status = true;
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return new JsonResult { Data = new { status = status, message = message } };
        }

        // delete
        [HttpPost]
        public JsonResult DeleteContact(int contactID)
        {
            bool status = false;
            string message = "";
            try
            {
                using (MyDatabaseEntities dc = new MyDatabaseEntities())
                {
                    var v = dc.Contacts.Where(a => a.ContactID.Equals(contactID)).FirstOrDefault();
                    if (v != null)
                    {
                        dc.Contacts.Remove(v);
                        dc.SaveChanges();
                        status = true;
                    }
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
            }
            return new JsonResult { Data = new { status = status, message = message } };
        }
    }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial