private bool DuplicateValues(SpecimenType specimenType) { var specimenTypeAlreadyExists = _context.SpecimenTypes.Where(st => (st.Description == specimenType.Description || st.Code == specimenType.Code) && st.Id != specimenType.Id); return(specimenTypeAlreadyExists.Any()); }
public static SpecimenTypeViewModel ToSpecimenTypeViewModel(this SpecimenType specimenType) { if (Equals(specimenType, null)) { return(null); } var specimenTypeViewModel = new SpecimenTypeViewModel() { Description = specimenType.Description, Id = specimenType.Id, Code = specimenType.Code, Active = specimenType.Active }; return(specimenTypeViewModel); }
/// <inheritdoc/> public string ToDelimitedString() { CultureInfo culture = CultureInfo.CurrentCulture; return(string.Format( culture, StringHelper.StringFormatSequence(0, 36, Configuration.FieldSeparator), Id, SetIdSpm.HasValue ? SetIdSpm.Value.ToString(culture) : null, SpecimenId?.ToDelimitedString(), SpecimenParentIds != null ? string.Join(Configuration.FieldRepeatSeparator, SpecimenParentIds.Select(x => x.ToDelimitedString())) : null, SpecimenType?.ToDelimitedString(), SpecimenTypeModifier != null ? string.Join(Configuration.FieldRepeatSeparator, SpecimenTypeModifier.Select(x => x.ToDelimitedString())) : null, SpecimenAdditives != null ? string.Join(Configuration.FieldRepeatSeparator, SpecimenAdditives.Select(x => x.ToDelimitedString())) : null, SpecimenCollectionMethod?.ToDelimitedString(), SpecimenSourceSite?.ToDelimitedString(), SpecimenSourceSiteModifier != null ? string.Join(Configuration.FieldRepeatSeparator, SpecimenSourceSiteModifier.Select(x => x.ToDelimitedString())) : null, SpecimenCollectionSite?.ToDelimitedString(), SpecimenRole != null ? string.Join(Configuration.FieldRepeatSeparator, SpecimenRole.Select(x => x.ToDelimitedString())) : null, SpecimenCollectionAmount?.ToDelimitedString(), GroupedSpecimenCount.HasValue ? GroupedSpecimenCount.Value.ToString(Consts.NumericFormat, culture) : null, SpecimenDescription != null ? string.Join(Configuration.FieldRepeatSeparator, SpecimenDescription) : null, SpecimenHandlingCode != null ? string.Join(Configuration.FieldRepeatSeparator, SpecimenHandlingCode.Select(x => x.ToDelimitedString())) : null, SpecimenRiskCode != null ? string.Join(Configuration.FieldRepeatSeparator, SpecimenRiskCode.Select(x => x.ToDelimitedString())) : null, SpecimenCollectionDateTime?.ToDelimitedString(), SpecimenReceivedDateTime.HasValue ? SpecimenReceivedDateTime.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null, SpecimenExpirationDateTime.HasValue ? SpecimenExpirationDateTime.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null, SpecimenAvailability, SpecimenRejectReason != null ? string.Join(Configuration.FieldRepeatSeparator, SpecimenRejectReason.Select(x => x.ToDelimitedString())) : null, SpecimenQuality?.ToDelimitedString(), SpecimenAppropriateness?.ToDelimitedString(), SpecimenCondition != null ? string.Join(Configuration.FieldRepeatSeparator, SpecimenCondition.Select(x => x.ToDelimitedString())) : null, SpecimenCurrentQuantity?.ToDelimitedString(), NumberOfSpecimenContainers.HasValue ? NumberOfSpecimenContainers.Value.ToString(Consts.NumericFormat, culture) : null, ContainerType?.ToDelimitedString(), ContainerCondition?.ToDelimitedString(), SpecimenChildRole?.ToDelimitedString(), AccessionId != null ? string.Join(Configuration.FieldRepeatSeparator, AccessionId.Select(x => x.ToDelimitedString())) : null, OtherSpecimenId != null ? string.Join(Configuration.FieldRepeatSeparator, OtherSpecimenId.Select(x => x.ToDelimitedString())) : null, ShipmentId?.ToDelimitedString(), CultureStartDateTime.HasValue ? CultureStartDateTime.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null, CultureFinalDateTime.HasValue ? CultureFinalDateTime.Value.ToString(Consts.DateTimeFormatPrecisionSecond, culture) : null, ActionCode ).TrimEnd(Configuration.FieldSeparator.ToCharArray())); }
public async Task <IActionResult> PostSpecimenType([FromBody] SpecimenType specimenType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (DuplicateValues(specimenType)) { return(BadRequest(specimenType)); } specimenType.DateCreated = DateTime.Now; specimenType.CreatedBy = HttpContext.User.Identity.Name; _context.SpecimenTypes.Add(specimenType); await _context.SaveChangesAsync(); return(CreatedAtAction("GetSpecimenType", new { id = specimenType.Id }, specimenType)); }
public async Task <IActionResult> PutSpecimenType([FromRoute] int id, [FromBody] SpecimenType specimenType) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != specimenType.Id) { return(BadRequest()); } if (DuplicateValues(specimenType)) { return(BadRequest(specimenType)); } specimenType.DateModified = DateTime.Now; specimenType.ModifiedBy = HttpContext.User.Identity.Name; _context.Entry(specimenType).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!SpecimenTypeExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }