ASP.net_Editable_Demo.FakeDatabase.add C# (CSharp) Метод

add() публичный статический Метод

public static add ( string>.Dictionary data ) : int
data string>.Dictionary
Результат int
        public static int add(Dictionary<string, string> data)
        {
            Employee e = new Employee 
            {
                EmpId = keyIndex,
                FirstName = data["First Name"],
                LastName = data["Last Name"],
                JobTitle = data["Job Title"],
                DOB = DateTime.Parse(data["DOB"]),
                Status = data["Status"]
            };
            db.Add(keyIndex, e);
            keyIndex++;
            return db.Count;
        }

Usage Example

        public void ProcessRequest(HttpContext context)
        {
            var contextData = context.Request;
            var sr          = new StreamReader(contextData.InputStream);
            var stream      = sr.ReadToEnd();

            var javaScriptSerializer = new JavaScriptSerializer();
            var data = javaScriptSerializer.Deserialize <Dictionary <string, string> >(stream);

            string command = data["command"];
            string table   = data["table"];

            string response     = "";
            string message      = "";
            object responseData = null;

            try
            {
                //employee table operations
                if (table == "Employees")
                {
                    if (command == "Add")
                    {
                        response     = "Update";
                        responseData = "{\"EmpId\":" + FakeDatabase.add(data) + "}";
                    }

                    if (command == "Delete")
                    {
                        FakeDatabase.delete(data);
                    }
                    if (command == "Update")
                    {
                        FakeDatabase.update(data);
                    }

                    if (command == "Load")
                    {
                        response     = "Load";
                        responseData = FakeDatabase.select(data);
                    }
                }

                response = response == "" ? "Success" : response;
                message  = "Hell Yeah!";
            }
            catch (Exception e)
            {
                response = "Error";
                message  = e.Message;
            }

            context.Response.ContentType = "application/json; charset=utf-8";

            Dictionary <string, object> responseItems = new Dictionary <string, object>();

            if (response != null)
            {
                responseItems.Add("response", response);
            }
            if (message != null)
            {
                responseItems.Add("message", message);
            }
            if (responseData != null)
            {
                responseItems.Add("responseData", responseData);
            }
            //string test = javaScriptSerializer.Serialize(responseItems);
            context.Response.Write(javaScriptSerializer.Serialize(responseItems));
        }