public void AddorUpdateSiteProcessingType(SiteItems siteItem, int siteId, string updatedBy) { LogMessage("AddorUpdateSiteProcessingType (SiteProcessingTypeManager)"); var existingSiteProcessingTypes = base.Repository.GetAllBySiteId(siteId); foreach (var item in existingSiteProcessingTypes) { base.BatchRemove(item); } var newSiteProcessingTypes = siteItem.ProcessingTypes.Where(x => x.IsSelected == true).ToList(); foreach (var objProcessingType in newSiteProcessingTypes) { SiteProcessingType siteProcessingType = new SiteProcessingType(); siteProcessingType.Id = Guid.NewGuid(); siteProcessingType.ProcessingTypeId = objProcessingType.Id; siteProcessingType.SiteId = siteId; siteProcessingType.CreatedBy = updatedBy; siteProcessingType.CreatedDate = DateTime.Now; siteProcessingType.UpdatedBy = updatedBy; siteProcessingType.UpdatedDate = DateTime.Now; base.BatchAdd(siteProcessingType); } base.Repository.SaveChanges(); }
public async Task <ServiceResponse <SiteItems> > SaveAsync(SiteItems siteItem) { DateTime startTime = DateTime.Now; try { var siteFacade = this.Container.GetInstance <SiteFacade>(); var site = await siteFacade.SaveAsync(siteItem, Email); base.LogMessage("SaveAsync", DateTime.Now - startTime); this.SendInvalidation(); return(new ServiceResponse <SiteItems>() { Item = ModelConversions.Convert(site, false, false) }); } catch (Exception ex) { return(new ServiceResponse <SiteItems>() { HasError = true, Message = ex.Message }); } }
/// <summary> /// Add new site record /// </summary> /// <param name="siteItem"></param> /// <param name="email"></param> /// <returns></returns> public Site Add(SiteItems siteItem, string email) { Site site = new Site(); site.Name = siteItem.SiteName; site.StartDate = Convert.ToDateTime(siteItem.SiteStartDate); site.IsPrimarySite = siteItem.SiteIsPrimarySite; site.ClinicalPopulationTypeId = siteItem.SiteClinicalPopulationType == null ? default(int?) : siteItem.SiteClinicalPopulationType.Id; site.CollectionProductTypeId = siteItem.SiteCollectionProductType == null ? default(int?) : siteItem.SiteCollectionProductType.Id; site.CBCollectionTypeId = siteItem.SiteCBCollectionType == null ? default(int?) : siteItem.SiteCBCollectionType.Id; site.CBUnitTypeId = siteItem.SiteCBUnitType == null ? default(int?) : siteItem.SiteCBUnitType.Id; //site.CBUnitsBanked = siteItem.SiteUnitsBanked; //if (!string.IsNullOrWhiteSpace(siteItem.SiteUnitsBankedDate)) //{ // site.CBUnitsBankDate = Convert.ToDateTime(siteItem.SiteUnitsBankedDate); //} site.CreatedBy = email; site.CreatedDate = DateTime.Now; if (siteItem.SiteAddresses != null) { site.SiteAddresses = new List <SiteAddress>(); foreach (var siteAddressItem in siteItem.SiteAddresses) { Address address = new Address(); address.AddressTypeId = siteAddressItem.Address.AddressType.Id; address.Street1 = siteAddressItem.Address.Street1; address.Street2 = siteAddressItem.Address.Street2; address.City = siteAddressItem.Address.City; address.StateId = siteAddressItem.Address.State != null ? siteAddressItem.Address.State.Id : (int?)null; address.Province = siteAddressItem.Address.Province; address.ZipCode = siteAddressItem.Address.ZipCode; address.CountryId = siteAddressItem.Address.Country.Id; address.Phone = siteItem.SitePhone; address.CreatedBy = email; address.CreatedDate = DateTime.Now; SiteAddress siteAddress = new SiteAddress(); siteAddress.Address = address; siteAddress.CreatedBy = email; siteAddress.IsPrimaryAddress = false; siteAddress.CreatedDate = DateTime.Now; site.SiteAddresses.Add(siteAddress); } } base.Repository.Add(site); return(site); }
/// <summary> /// Saves new Site /// </summary> /// <param name="siteItem"></param> /// <returns></returns> public async Task <Site> SaveAsync(SiteItems siteItem, string email) { var siteManager = this.container.GetInstance <SiteManager>(); var site = siteManager.Save(siteItem, email); ManageSiteAddresses(siteItem, site, email); var siteScopeTypeManager = this.container.GetInstance <SiteScopeTypeManager>(); siteScopeTypeManager.AddorUpdateSiteScopeType(siteItem, site.Id, email); var siteTransplantTypeManager = this.container.GetInstance <SiteTransplantTypeManager>(); siteTransplantTypeManager.AddorUpdateSiteTransplantType(siteItem, site.Id, email); var siteClinicalTypeManager = this.container.GetInstance <SiteClinicalTypeManager>(); siteClinicalTypeManager.AddorUpdateSiteClinicalType(siteItem, site.Id, email); var siteProcessingTypeManager = this.container.GetInstance <SiteProcessingTypeManager>(); siteProcessingTypeManager.AddorUpdateSiteProcessingType(siteItem, site.Id, email); if (siteItem.SiteFacilityId != 0) { var facilitySiteManager = this.container.GetInstance <FacilitySiteManager>(); var facilitySites = facilitySiteManager.GetBySiteId(site.Id); if (facilitySites != null) { foreach (var facSite in facilitySites) { facilitySiteManager.Remove(facSite.Id); } } facilitySiteManager.AddRelation(site.Id, siteItem.SiteFacilityId, email); } await this.InvalidateCacheAsync(email); //var temp = siteManager.GetById(site.Id); return(site); }
public Site Save(SiteItems siteItem, string email) { LogMessage("Save (SiteManager)"); Site site = null; if (siteItem.SiteId != 0) { site = this.Update(siteItem, email); } else { site = this.Add(siteItem, email); } return(site); }
private void ManageSiteAddresses(SiteItems siteItem, Site site, string email) { var siteManager = this.container.GetInstance <SiteManager>(); var siteAddressManager = this.container.GetInstance <SiteAddressManager>(); var addressManager = this.container.GetInstance <AddressManager>(); var distanceManager = this.container.GetInstance <DistanceManager>(); if (siteItem.SiteId != 0) // site update case { var tempSite = siteManager.GetById(siteItem.SiteId); if (tempSite != null && tempSite.SiteAddresses != null) { var primaryAddress = tempSite.SiteAddresses.FirstOrDefault(x => x.IsPrimaryAddress == true); if (primaryAddress != null) // update primary address { var address = addressManager.GetById(primaryAddress.AddressId); address.Street1 = siteItem.SiteStreetAddress1; address.Street2 = siteItem.SiteStreetAddress2; address.City = siteItem.SiteCity; address.StateId = siteItem.SiteState?.Id; address.Province = siteItem.SiteProvince; address.Phone = siteItem.SitePhone; address.ZipCode = siteItem.SiteZip; address.CountryId = siteItem.SiteCountry?.Id ?? 0; address.UpdatedBy = email; address.UpdatedDate = DateTime.Now; addressManager.Save(address); } else //add primary address { var address = new Address { AddressTypeId = (int)Constants.AddressType.Office, Street1 = siteItem.SiteStreetAddress1, Street2 = siteItem.SiteStreetAddress2, City = siteItem.SiteCity, StateId = siteItem.SiteState?.Id, Province = siteItem.SiteProvince, ZipCode = siteItem.SiteZip, CountryId = siteItem.SiteCountry?.Id ?? 0, Phone = siteItem.SitePhone, CreatedBy = email, CreatedDate = DateTime.Now }; addressManager.Add(address); var siteAddress = new SiteAddress { SiteId = siteItem.SiteId, AddressId = address.Id, IsPrimaryAddress = true, CreatedBy = email, CreatedDate = DateTime.Now }; siteAddressManager.Add(siteAddress); } if (siteItem.SiteAddresses != null) { foreach (var siteAddressItem in siteItem.SiteAddresses) { if (siteAddressItem.Id == 0) //new site address { var address = new Address { AddressTypeId = siteAddressItem.Address.AddressType.Id, Street1 = siteAddressItem.Address.Street1, Street2 = siteAddressItem.Address.Street2, City = siteAddressItem.Address.City, StateId = siteAddressItem.Address.State?.Id, Province = siteAddressItem.Address.Province, ZipCode = siteAddressItem.Address.ZipCode, CountryId = siteAddressItem.Address.Country.Id, Phone = siteAddressItem.Address.Phone, CreatedBy = email, CreatedDate = DateTime.Now }; //address.Phone = siteAddressItem.Address.Phone; addressManager.Add(address); var siteAddress = new SiteAddress { SiteId = siteItem.SiteId, AddressId = address.Id, IsPrimaryAddress = false, CreatedBy = email, CreatedDate = DateTime.Now }; siteAddressManager.Add(siteAddress); } else // update site address { var address = addressManager.GetById(siteAddressItem.AddressId); address.Street1 = siteAddressItem.Address.Street1; address.Street2 = siteAddressItem.Address.Street2; address.City = siteAddressItem.Address.City; address.StateId = siteAddressItem.Address.State?.Id; address.Province = siteAddressItem.Address.Province; address.Phone = siteAddressItem.Address.Phone; address.ZipCode = siteAddressItem.Address.ZipCode; address.CountryId = siteAddressItem.Address.Country?.Id; address.UpdatedBy = email; address.UpdatedDate = DateTime.Now; addressManager.Save(address); } } // delete site address foreach (var siteAddress in tempSite.SiteAddresses.Where(x => x.IsPrimaryAddress != true)) { var found = siteItem.SiteAddresses.Any(x => x.Id == siteAddress.Id); if (!found) { var distanceList = siteAddress.Distances; if (distanceList != null) { foreach (var distance in distanceList) { distanceManager.Remove(distance.Id); } } siteAddressManager.Remove(siteAddress.Id); } } } this.InvalidateCache(email); } } else // new addresses for new site { var address = new Address { AddressTypeId = (int)Constants.AddressType.Office, Street1 = siteItem.SiteStreetAddress1, Street2 = siteItem.SiteStreetAddress2, City = siteItem.SiteCity, StateId = siteItem.SiteState?.Id, Province = siteItem.SiteProvince, ZipCode = siteItem.SiteZip, CountryId = siteItem.SiteCountry?.Id ?? 0, Phone = siteItem.SitePhone, CreatedBy = email, CreatedDate = DateTime.Now }; //address.Phone = site.Phone; addressManager.Add(address); var siteAddress = new SiteAddress { SiteId = site.Id, AddressId = address.Id, IsPrimaryAddress = true, CreatedBy = email, CreatedDate = DateTime.Now }; siteAddressManager.Add(siteAddress); } }
/// <summary> /// Update site record /// </summary> /// <param name="siteItem"></param> /// <param name="email"></param> /// <returns></returns> public Site Update(SiteItems siteItem, string email) { var site = base.Repository.GetById(siteItem.SiteId); site.Name = siteItem.SiteName; site.StartDate = Convert.ToDateTime(siteItem.SiteStartDate); //site.StreetAddress1 = siteItem.SiteStreetAddress1; //site.StreetAddress2 = siteItem.SiteStreetAddress2; //site.City = siteItem.SiteCity; //site.Zip = siteItem.SiteZip; //site.StateId = siteItem.SiteState == null ? default(int?) : siteItem.SiteState.Id == 0 ? default(int?) : siteItem.SiteState.Id; //site.Province = siteItem.SiteProvince; //site.CountryId = siteItem.SiteCountry.Id; //site.Phone = siteItem.SitePhone; site.IsPrimarySite = siteItem.SiteIsPrimarySite; //site.ClinicalTypeId = siteItem.SiteClinicalType == null ? default(int?) : siteItem.SiteClinicalType.Id; //site.ProcessingTypeId = siteItem.SiteProcessingType == null ? default(int?) : siteItem.SiteProcessingType.Id; site.CollectionProductTypeId = siteItem.SiteCollectionProductType == null || siteItem.SiteCollectionProductType.Id == 0 ? default(int?) : siteItem.SiteCollectionProductType.Id; site.ClinicalPopulationTypeId = siteItem.SiteClinicalPopulationType == null || siteItem.SiteClinicalPopulationType.Id == 0 ? default(int?) : siteItem.SiteClinicalPopulationType.Id; //site.TransplantTypeId = siteItem.SiteTransplantType == null ? default(int?) : siteItem.SiteTransplantType.Id; site.CBCollectionTypeId = siteItem.SiteCBCollectionType == null || siteItem.SiteCBCollectionType.Id == 0 ? default(int?) : siteItem.SiteCBCollectionType.Id; site.CBUnitTypeId = siteItem.SiteCBUnitType == null || siteItem.SiteCBUnitType.Id == 0 ? default(int?) : siteItem.SiteCBUnitType.Id; site.CBUnitsBanked = siteItem.SiteUnitsBanked; if (!string.IsNullOrWhiteSpace(siteItem.SiteUnitsBankedDate)) { site.CBUnitsBankDate = Convert.ToDateTime(siteItem.SiteUnitsBankedDate); } if (site.SiteAddresses != null) { var address = site.SiteAddresses.FirstOrDefault(x => x.IsPrimaryAddress.GetValueOrDefault()); if (address != null) { address.Address.Street1 = siteItem.SiteStreetAddress1; address.Address.Street2 = siteItem.SiteStreetAddress2; address.Address.City = siteItem.SiteCity; address.Address.StateId = siteItem.SiteState == null ? default(int?) : siteItem.SiteState.Id == 0 ? default(int?) : siteItem.SiteState.Id; address.Address.ZipCode = siteItem.SiteZip; address.Address.CountryId = siteItem.SiteCountry.Id; address.Address.Phone = siteItem.SitePhone; address.Address.UpdatedBy = email; address.Address.UpdatedDate = DateTime.Now; } } else { site.SiteAddresses = new List <SiteAddress>(); foreach (var siteAddressItem in siteItem.SiteAddresses) { var siteAddress = new SiteAddress { Address = new Address { AddressTypeId = siteAddressItem.Address.AddressType.Id, Street1 = siteAddressItem.Address.Street1, Street2 = siteAddressItem.Address.Street2, City = siteAddressItem.Address.City, StateId = siteAddressItem.Address.State?.Id, Province = siteAddressItem.Address.Province, ZipCode = siteAddressItem.Address.ZipCode, CountryId = siteAddressItem.Address.Country.Id, Phone = siteItem.SitePhone, CreatedBy = email, CreatedDate = DateTime.Now }, CreatedBy = email, IsPrimaryAddress = false, CreatedDate = DateTime.Now }; site.SiteAddresses.Add(siteAddress); } } site.UpdatedBy = email; site.UpdatedDate = DateTime.Now; base.Repository.Save(site); return(site); }