public IHttpActionResult Update([FromUri] int modStructureId, [FromBody] ModStructureModel model) { try { var modStructure = _structuresService.GetModStructure(modStructureId); if (modStructure == null) { return(NotFound()); } Mapper.Map(model, modStructure, opt => opt.BeforeMap((src, dest) => { dest.InstrumentModStructures.Clear(); })); if (!_structuresService.IsModStructureExists(modStructure)) { _structuresService.UpdateModStructure(modStructure); var itemAttachments = model.Attachments.Where(info => info.Id != 0).Select(info => info.Id).ToList(); _structuresService.UpdateAssociations(modStructureId, itemAttachments); //var instrumentModStructures = model.InstrumentModStructures; //_structuresService.UpdateInstrumentModStructures(modStructureId, instrumentModStructures); } else { model.SetError("Name", "Duplicate Mod Structure name"); } return(Ok(model)); } catch (Exception) { return(InternalServerError()); } }
public IHttpActionResult Get(int modStructureId) { var modStructure = _structuresService.GetModStructure(modStructureId); if (modStructure == null) { return(NotFound()); } var model = new ModStructureModel(); Mapper.Map(modStructure, model); model.HasAssociations = _structuresService.HasAssociations(modStructure); return(Ok(model)); }
public IHttpActionResult Create([FromBody] ModStructureModel model) { try { var modStructure = new ModStructure(); Mapper.Map(model, modStructure); if (!_structuresService.IsModStructureExists(modStructure)) { _structuresService.CreateModStructure(modStructure); model.Id = modStructure.Id; } else { model.SetError("Name", string.Format("Mod Structure {0} is already in use.", model.Name)); } return(Ok(model)); } catch (Exception) { return(InternalServerError()); } }
private ExpandoObject GetModStructuresByBase(int ordinalPosition, string baseChar) { dynamic result = new ExpandoObject(); var items = _structuresService.GetAllModStructures().Where(m => m.Base == baseChar); var locatedModStructures = new List <ModStructureModel>(); result.Base = baseChar; result.OrdinalPosition = ordinalPosition; result.SelectedModStructure = ""; foreach (var item in items) { var modStructure = new ModStructureModel(); Mapper.Map(item, modStructure); locatedModStructures.Add(modStructure); if (locatedModStructures.Count == 1) { result.SelectedModStructure = locatedModStructures.Last(); } } result.ModStructures = locatedModStructures; return(result); }
public async Task <IHttpActionResult> Import() { var provider = new InMemoryMultipartFormDataStreamProvider(); await Request.Content.ReadAsMultipartAsync(provider); var model = new List <ImportedStrandViewModel>(); IEnumerable <StrandSheetModel> strandSheets; try { strandSheets = await ParseFile(provider.Files); } catch (Exception) { return(BadRequest("Uploaded file has incorrect format")); } foreach (var strandSheet in strandSheets) { var orientationModel = new OrientationModel { Name = strandSheet.Orientation }; var orientation = _strandsService.GetOrientationByName(strandSheet.Orientation); if (orientation == null) { orientationModel.SetError("", ""); } var targetModel = new TargetModel { Name = strandSheet.Target }; var target = _strandsService.GetTargetByName(strandSheet.Target); if (target == null) { targetModel.SetError("", ""); } var firstPosition = 1; if (strandSheet.Orientation == "Sense") { firstPosition = strandSheet.ModStructures.Count; } Mapper.Map(orientation, orientationModel); Mapper.Map(target, targetModel); var strandModel = new ImportedStrandViewModel { FirstPosition = firstPosition, Sequence = strandSheet.Sequence, ParentSequence = strandSheet.ParentSequence, GenomeNumber = strandSheet.GenomeNumber, GenomePosition = strandSheet.GenomePosition, Orientation = orientationModel, Target = targetModel, StrandModStructures = new List <StrandModStructureModel>() }; var ordinalPosition = 0; foreach (var modStructureName in strandSheet.ModStructures) { var modStructureModel = new ModStructureModel { Name = modStructureName }; var modStructure = _strandsService.GetModStructureByName(modStructureName); if (modStructure == null) { modStructureModel.SetError("", ""); } Mapper.Map(modStructure, modStructureModel); var strandModStructure = new StrandModStructureModel { ModStructure = modStructureModel, OrdinalPosition = ordinalPosition + 1 }; strandModel.StrandModStructures.Add(strandModStructure); ordinalPosition++; } model.Add(strandModel); } return(Ok(model)); }