public long Add(License obj) { try { return(_licenseRepository.Add(obj)); } catch (Exception ex) { throw ex; } }
public void Update(List <LicenseViewModel> newLicenses) { var licenses = _licenseRepository.GetAll(); var maxLicenseCOde = 0; if (licenses.Any()) { maxLicenseCOde = Convert.ToInt32(licenses.Max(x => Convert.ToInt32(x.LicenseC))); } //xoa foreach (var license in licenses) { if (newLicenses.Any(item => item.LicenseC == license.LicenseC) == false) { _licenseRepository.Delete(license); } } //update foreach (var item in newLicenses) { if (string.IsNullOrEmpty(item.LicenseC)) { var addItem = new License_M() { DisplayLineNo = item.DisplayLineNo, LicenseC = (++maxLicenseCOde).ToString(), LicenseN = item.LicenseN }; _licenseRepository.Add(addItem); } else { var updateLicense = licenses.Where(x => x.LicenseC == item.LicenseC).FirstOrDefault(); if (updateLicense != null) { updateLicense.DisplayLineNo = item.DisplayLineNo; updateLicense.LicenseN = item.LicenseN; _licenseRepository.Update(updateLicense); } } } SaveLicense(); }
public void Add(License license) { repository.Add(license); }