using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Xrm;
using Microsoft.Xrm.Client;


namespace ToolsCRM
{
    /// <summary>
    /// Summary description for InsertCompetitor
    /// </summary>
    public class InsertCompetitor : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
           // context.Response.Write("Hello World");
            //var title = context.Request["title"];


            var firma = context.Request["firma"];
            var miasto = context.Request["adres"];
            var kraj = context.Request["kraj"];
            
            var xrm = new XrmServiceContext("Xrm");
            
            var konkurenci = new Competitor
            {
                Name= firma,  
                Address1_City = miasto,
                Address1_County = kraj
            };
            xrm.AddObject(konkurenci);
            xrm.SaveChanges();
            
    
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}