public IHttpActionResult PostBuyer(Buyer buyer)
        {
            var    pageName = Request.RequestUri.LocalPath.getRouteName();
            Object obj      = null;
            var    UserId   = 0;

            if (Request.Headers.Contains("Email"))
            {
                var email = ((string[])(Request.Headers.GetValues("Email")))[0].ToString();
                UserId = db.Users.Where(x => x.IsActive == true && x.Email.Contains(email)).FirstOrDefault().Id;
            }
            buyer.CreatedOn = System.DateTime.UtcNow;
            buyer.UpdatedOn = System.DateTime.UtcNow;
            db.Buyers.Add(buyer);
            try
            {
                db.SaveChanges();
            }
            catch (Exception ex) { obj = ex; }
            finally
            {
                if (obj == null)
                {
                    var logTable = Newtonsoft.Json.JsonConvert.SerializeObject(buyer, new JsonSerializerSettings()
                    {
                        PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                        Formatting = Formatting.Indented
                    });
                    var flag = buyer.CreateLog(pageName, logTable, UserId);
                }
            }
            return(Ok(buyer));
        }
        public IHttpActionResult PutBuyer(int id, Buyer buyer)
        {
            var    list     = new List <Buyer>();
            var    pageName = Request.RequestUri.LocalPath.getRouteName();
            Object obj      = null;
            var    UserId   = 0;

            if (Request.Headers.Contains("Email"))
            {
                var email = ((string[])(Request.Headers.GetValues("Email")))[0].ToString();
                UserId = db.Users.Where(x => x.IsActive == true && x.Email.Contains(email)).FirstOrDefault().Id;
            }
            string logTable = "";
            var    data     = db.Buyers.Where(x => x.IsActive == true && x.Id == id).FirstOrDefault();

            data.IsActive  = true;
            data.Name      = buyer.Name;
            data.BuyLimit  = buyer.BuyLimit;
            data.Id        = buyer.Id;
            data.UpdatedOn = System.DateTime.UtcNow;
            try
            {
                db.SaveChanges();
                list.Add(buyer);
                return(Ok(data));
            }
            catch (DbUpdateConcurrencyException ex)
            {
                obj = ex;
            }

            finally
            {
                if (obj == null)
                {
                    logTable = "";
                    var change = list.ToDataTables().getChangedRecords();
                    var c      = change.Count() / 2;
                    for (var i = 0; i < c; i++)
                    {
                        logTable += change[i].Fieldname + " Old Value=[" + change[i].FieldValue + "] New Value=[" + change[i + c].FieldValue + "], ";
                    }
                    //logTable = Newtonsoft.Json.JsonConvert.SerializeObject(change);
                    var flag = buyer.CreateLog(pageName, logTable, UserId);
                }
            }
            return(Ok(data));
        }