public int HospitalNewRecord(string name, decimal numberOfBed, string phoneI, string phoneII, string phoneIII, string mail, string website, string city, string county, string address) { if (!string.IsNullOrEmpty(name) && !string.IsNullOrWhiteSpace(name) && !string.IsNullOrEmpty(city) && !string.IsNullOrWhiteSpace(city) && !string.IsNullOrEmpty(county) && !string.IsNullOrWhiteSpace(county)) { string tempPhoneI; string tempPhoneII; string tempPhoneIII; string tempMail; string tempWebsite; string tempAddress; if (string.IsNullOrEmpty(phoneI.Trim())) { tempPhoneI = null; } else { tempPhoneI = phoneI; } if (string.IsNullOrEmpty(phoneII.Trim())) { tempPhoneII = null; } else { tempPhoneII = phoneII; } if (string.IsNullOrEmpty(phoneIII.Trim())) { tempPhoneIII = null; } else { tempPhoneIII = phoneIII; } if (string.IsNullOrEmpty(mail.Trim())) { tempMail = null; } else { tempMail = mail; } if (string.IsNullOrEmpty(website.Trim())) { tempWebsite = null; } else { tempWebsite = website; } if (string.IsNullOrEmpty(address.Trim())) { tempAddress = null; } else { tempAddress = address; } using (RepositoryHospital repositoryHospital = new RepositoryHospital()) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.Name == name)) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.PhoneI == phoneI)) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.PhoneII == phoneII)) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.PhoneIII == phoneIII)) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.Mail == mail)) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.Address == address)) { Hospital hospital = new Hospital() { Id = Guid.NewGuid(), Name = name, NumberOfBed = (int)numberOfBed, PhoneI = tempPhoneI, PhoneII = tempPhoneII, PhoneIII = tempPhoneIII, Mail = tempMail, Website = tempWebsite, City = city, County = county, Address = tempAddress, Picture = BLLHelper.DefaultHospitalPic() }; repositoryHospital.CUDOperation(hospital, EntityState.Added); return(repositoryHospital.SaveChanges()); } else { return(-109); } } else { return(-108); } } else { return(-107); } } else { return(-106); } } else { return(-105); } } else { return(-104); } } } else { return(-1); } }
public int HospitalUpdateRecord(Hospital hospital, string name, decimal numberOfBed, string phoneI, string phoneII, string phoneIII, string mail, string website, string city, string county, string address) { if (!string.IsNullOrEmpty(name) && !string.IsNullOrWhiteSpace(name) && !string.IsNullOrEmpty(city) && !string.IsNullOrWhiteSpace(city) && !string.IsNullOrEmpty(county) && !string.IsNullOrWhiteSpace(county) && hospital != null) { string tempPhoneI; string tempPhoneII; string tempPhoneIII; string tempMail; string tempWebsite; string tempAddress; if (string.IsNullOrEmpty(phoneI.Trim())) { tempPhoneI = null; } else { tempPhoneI = phoneI; } if (string.IsNullOrEmpty(phoneII.Trim())) { tempPhoneII = null; } else { tempPhoneII = phoneII; } if (string.IsNullOrEmpty(phoneIII.Trim())) { tempPhoneIII = null; } else { tempPhoneIII = phoneIII; } if (string.IsNullOrEmpty(mail.Trim())) { tempMail = null; } else { tempMail = mail; } if (string.IsNullOrEmpty(website.Trim())) { tempWebsite = null; } else { tempWebsite = website; } if (string.IsNullOrEmpty(address.Trim())) { tempAddress = null; } else { tempAddress = address; } using (RepositoryHospital repositoryHospital = new RepositoryHospital()) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.Id != hospital.Id && I.Name == name)) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.Id != hospital.Id && I.PhoneI == phoneI)) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.Id != hospital.Id && I.PhoneII == phoneII)) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.Id != hospital.Id && I.PhoneIII == phoneIII)) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.Id != hospital.Id && I.Mail == mail)) { if (!repositoryHospital.AnyWithExplicitLoad(I => I.Id != hospital.Id && I.Address == address)) { hospital.Name = name; hospital.NumberOfBed = (int)numberOfBed; hospital.PhoneI = tempPhoneI; hospital.PhoneII = tempPhoneII; hospital.PhoneIII = tempPhoneIII; hospital.Mail = tempMail; hospital.Website = tempWebsite; hospital.City = city; hospital.County = county; hospital.Address = tempAddress; hospital.UpdateTime = DateTime.Now; repositoryHospital.CUDOperation(hospital, EntityState.Modified); return(repositoryHospital.SaveChanges()); } else { return(-109); } } else { return(-108); } } else { return(-107); } } else { return(-106); } } else { return(-105); } } else { return(-104); } } } else { return(-1); } }