public void Update_Client(ClientViewModel clientview)
        {
            Client client;
            client = (clientview.Id > 0) ? db.Clients.Find(clientview.Id) :  client = new Client();

            client.Clientname = clientview.Clientname;
            client.Description = clientview.Description;
            client.CageCode = clientview.CageCode;
            client.SICCode = clientview.SICCode;
            client.CompanyType = clientview.CompanyType;
            client.SalesTaxRate = clientview.SalesTaxRate;
            if (client.Status == null)
                client.Status = "DEMO";
            client.ExpDate = DateTime.Now.AddMonths(1);
            Address address;

            address = (clientview.Id > 0) ? client.Addresses.FirstOrDefault() : new Address();

            address.Address1 = clientview.Address1;
            address.Address2 = clientview.Address2;
            address.City = clientview.City;
            address.State = clientview.State;
            address.PostalCode = clientview.PostalCode;
            address.Province = clientview.Province;
            address.Country = clientview.Country;
            address.AddressType = Address_Types.Corporate;
            Option opts;
            opts = (clientview.Id > 0) ? client.Options.FirstOrDefault() : new Option();
            opts.Item = true;
            opts.Purchasing = true;
            opts.Sales = true;
            opts.Warehouse = false;

            if (clientview.Id > 0)
            {
                db.Entry(address).State = EntityState.Modified;
                db.Entry(client).State = EntityState.Modified;
                db.Entry(opts).State = EntityState.Modified;
             }
            else
            {
                License lic =  new License();
                lic.Maximum_Installs = 1;
                lic.Current_Installs = 0;
                lic.Cost = 0;
                lic.Period = 0;
                lic.DueDate = DateTime.Now.AddMonths(1);
                lic.ProductKey = Guid.NewGuid().ToString();
                lic.SystemName = "BLSInventory";
                lic.SubSystem = "Item";
                client.Licenses.Add(lic);
                //if (clientview.Purchasing)
                //{
                    License plic = new License();
                    lic.CopyPropertiesTo<License, License>(plic);
                    plic.SubSystem = "Purchasing";
                    client.Licenses.Add(plic);
                //}
                //if (clientview.Sales)
                //{
                    License slic = new License();
                    lic.CopyPropertiesTo<License, License>(slic);
                    slic.SubSystem = "Sales";
                    client.Licenses.Add(slic);
                //}
                if (clientview.Warehouse)
                {
                    License wlic = new License();
                    lic.CopyPropertiesTo<License, License>(wlic);
                    wlic.SubSystem = "Warehouse";
                    client.Licenses.Add(wlic);
                }
                client.Addresses.Add(address);
                opts.Demo = true;
                opts.ExpDate = DateTime.Now.AddMonths(1);
                client.Options.Add(opts);
                db.Clients.Add(client);
            }

            try
            {
                db.SaveChanges();
                db.Entry(client).GetDatabaseValues();
                Session["ParentId"] = client.Id.ToString();
            }
            catch (DbEntityValidationException e)
            {
                return;
            }
        }