private bool UpdateDm(string code, string name, string chartOfAccount, string remark, string registrationNumber,
                              string contactPerson, string address1, string address2, string city, int postCode, string country, string state,
                              string phoneNumber, string fax, string email, string website, string taxCode, string taxNumber,
                              string taxExpiryDate, bool status)
        {
            bool res = false;

            try
            {
                Supplier supplier = _context.Supplier.FirstOrDefault(m => m.Code.Equals(code));

                OldDataSupplier oldData = new OldDataSupplier();
                oldData.Code               = supplier.Code;
                oldData.Name               = supplier.Name;
                oldData.ChartOfAccount     = chartOfAccount;
                oldData.Remark             = remark;
                oldData.RegistrationNumber = registrationNumber;
                oldData.ContactPerson      = contactPerson;
                oldData.Address1           = address1;
                oldData.Address2           = address2;
                oldData.City               = city;
                oldData.PostCode           = postCode;
                oldData.Country            = country;
                oldData.State              = state;
                oldData.PhoneNumber        = phoneNumber;
                oldData.Fax           = fax;
                oldData.Email         = email;
                oldData.Website       = website;
                oldData.TaxCode       = taxCode;
                oldData.TaxNumber     = taxNumber;
                oldData.TaxExpiryDate = Convert.ToDateTime(taxExpiryDate);
                oldData.Status        = status;

                string oldJson = JsonConvert.SerializeObject(oldData);
                string newJson = JsonConvert.SerializeObject(supplier);

                if (supplier != null)
                {
                    supplier.Code               = code;
                    supplier.Name               = name;
                    supplier.ChartOfAccount     = chartOfAccount;
                    supplier.Remark             = remark;
                    supplier.RegistrationNumber = registrationNumber;
                    supplier.ContactPerson      = contactPerson;
                    supplier.Address1           = address1;
                    supplier.Address2           = address2;
                    supplier.City               = city;
                    supplier.PostCode           = postCode;
                    supplier.Country            = country;
                    supplier.State              = state;
                    supplier.PhoneNumber        = phoneNumber;
                    supplier.Fax              = fax;
                    supplier.Email            = email;
                    supplier.Website          = website;
                    supplier.TaxCode          = taxCode;
                    supplier.TaxNumber        = taxNumber;
                    supplier.TaxExpiryDate    = Convert.ToDateTime(taxExpiryDate);
                    supplier.Status           = status;
                    supplier.ModifiedDatetime = DateTime.UtcNow;
                    supplier.ModifiedBy       = _configuration.GetValue <string>("HardcodeValue:Modifiedby");
                    AuditService.InsertActionLog(supplier.CompanyId, supplier.CreatedBy, "Import Update", "Supplier", oldJson, newJson);
                    _context.SaveChanges();
                    res = true;
                }
            }
            catch (Exception ex)
            {
                res = false;
            }

            return(res);
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Code,Name,ChartOfAccount,Remark,RegistrationNumber,ContactPerson,Address1,Address2,City,PostCode,Country,State,PhoneNumber,Fax,Email,Website,TaxCode,TaxNumber,TaxExpiryDate,Status, CreatedBy,CreatedDatetime,ModifiedBy,ModifeidDatetime")] Supplier supplier)
        {
            try
            {
                bool isCodeExist = _context.MasterAssetBrand.Any(m => m.Code.Equals(supplier.Code) && !m.Id.Equals(id));
                if (isCodeExist)
                {
                    ModelState.AddModelError("Code", "Code Already Exists!");
                    return(View(supplier));
                    //return RedirectToAction(nameof(Index), new { error = "Code exists" });
                }

                Supplier db_supplier = _context.Supplier.FirstOrDefault(m => m.Id.Equals(supplier.Id));
                if (supplier == null || id != supplier.Id)
                {
                    return(NotFound());
                }

                OldDataSupplier oldData = new OldDataSupplier();
                oldData.Code               = db_supplier.Code;
                oldData.Name               = db_supplier.Name;
                oldData.ChartOfAccount     = db_supplier.ChartOfAccount;
                oldData.Remark             = db_supplier.Remark;
                oldData.RegistrationNumber = db_supplier.RegistrationNumber;
                oldData.ContactPerson      = db_supplier.ContactPerson;
                oldData.Address1           = db_supplier.Address1;
                oldData.Address2           = db_supplier.Address2;
                oldData.City               = db_supplier.City;
                oldData.PostCode           = db_supplier.PostCode;
                oldData.Country            = db_supplier.Country;
                oldData.State              = db_supplier.State;
                oldData.PhoneNumber        = db_supplier.PhoneNumber;
                oldData.Fax           = db_supplier.Fax;
                oldData.Email         = db_supplier.Email;
                oldData.Website       = db_supplier.Website;
                oldData.TaxCode       = db_supplier.TaxCode;
                oldData.TaxNumber     = db_supplier.TaxNumber;
                oldData.TaxExpiryDate = db_supplier.TaxExpiryDate;
                oldData.Status        = db_supplier.Status;

                string oldJson = JsonConvert.SerializeObject(oldData);
                string newJson = JsonConvert.SerializeObject(supplier);

                db_supplier.Code               = supplier.Code;
                db_supplier.Name               = supplier.Name;
                db_supplier.ChartOfAccount     = supplier.ChartOfAccount;
                db_supplier.Remark             = supplier.Remark;
                db_supplier.RegistrationNumber = supplier.RegistrationNumber;
                db_supplier.ContactPerson      = supplier.ContactPerson;
                db_supplier.Address1           = supplier.Address1;
                db_supplier.Address2           = supplier.Address2;
                db_supplier.City               = supplier.City;
                db_supplier.PostCode           = supplier.PostCode;
                db_supplier.Country            = supplier.Country;
                db_supplier.State              = supplier.State;
                db_supplier.PhoneNumber        = supplier.PhoneNumber;
                db_supplier.Fax              = supplier.Fax;
                db_supplier.Email            = supplier.Email;
                db_supplier.Website          = supplier.Website;
                db_supplier.TaxCode          = supplier.TaxCode;
                db_supplier.TaxNumber        = supplier.TaxNumber;
                db_supplier.TaxExpiryDate    = supplier.TaxExpiryDate;
                db_supplier.Status           = supplier.Status;
                db_supplier.ModifiedBy       = _configuration.GetValue <string>("HardcodeValue:Createdby");
                db_supplier.ModifiedDatetime = DateTime.UtcNow;
                AuditService.InsertActionLog(db_supplier.CompanyId, db_supplier.CreatedBy, "Edit", "Supplier", oldJson, newJson);

                _context.Update(db_supplier);
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SupplierExists(supplier.Id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
            return(RedirectToAction(nameof(Index)));
        }