/// <summary> /// Validating the Customer /// </summary> /// <param name="customerunit"></param> /// <returns></returns> protected virtual async Task ValidateCustomerUnitAsync(CustomerUnit customerunit) { if (CustomerUnitRepository != null) { var customer = (await CustomerUnitRepository.GetAllListAsync(p => p.LastName == customerunit.LastName && p.OrganizationUnitId == customerunit.OrganizationUnitId)); if (customerunit.Id == 0) { if (customer.Count > 0) { throw new UserFriendlyException(L("Duplicate Name", customerunit.LastName)); } } else { if (customer.FirstOrDefault(p => p.Id != customerunit.Id && p.LastName == customerunit.LastName) != null) { throw new UserFriendlyException(L("Duplicate Name", customerunit.LastName)); } } } }
/// <summary> /// Updating Customer Details in CustomerTable /// </summary> /// <param name="customerunit"></param> /// <returns></returns> public virtual async Task UpdateAsync(CustomerUnit customerunit) { await ValidateCustomerUnitAsync(customerunit); await CustomerUnitRepository.UpdateAsync(customerunit); }