public static int CreatePayment(Payments payment) { using (VedantaEntities deo = new VedantaEntities()) { if (payment != null) { Payments oldPayments = deo.Payments.FirstOrDefault(py => py.BranchId == payment.BranchId && payment.Date == py.Date && payment.VoucherNo.Equals(py.VoucherNo, StringComparison.OrdinalIgnoreCase)); if (oldPayments == null) { deo.AddToPayments(payment); return(deo.SaveChanges()); } else { return(-1); } } } return(0); }