Ejemplo n.º 1
0
        public IHttpActionResult Update([FromUri] int targetId, [FromBody] TargetModel model)
        {
            var target = _targetsService.GetTarget(targetId);

            if (target == null)
            {
                return(NotFound());
            }

            Mapper.Map(model, target);
            if (!_targetsService.IsTargetExists(target))
            {
                _targetsService.UpdateTarget(target);
            }
            else
            {
                model.SetError("Name", "Duplicate target name");
            }

            return(Ok(model));
        }
Ejemplo n.º 2
0
        public IHttpActionResult Create([FromBody] TargetModel model)
        {
            try
            {
                var target = new Target();
                Mapper.Map(model, target);
                if (!_targetsService.IsTargetExists(target))
                {
                    _targetsService.CreateTarget(target);
                    model.Id = target.Id;
                }
                else
                {
                    model.SetError("Name", "Duplicate target name");
                }

                return(Ok(model));
            }
            catch
            {
                return(InternalServerError());
            }
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> ImportDuplexes()
        {
            var provider = new InMemoryMultipartFormDataStreamProvider();
            await Request.Content.ReadAsMultipartAsync(provider);

            IEnumerable <DuplexSheetModel> duplexSheets;

            try
            {
                duplexSheets = await ParseFile(provider.Files);
            }
            catch (Exception)
            {
                return(BadRequest("Uploaded file has incorrect format"));
            }

            var model = new List <ImportedDuplexModel>();

            foreach (var duplexSheet in duplexSheets)
            {
                var antiSenseStrandModel = new StrandModel {
                    StrandId = duplexSheet.AntiSenseStrandId
                };
                var antiSenseStrand = _duplexesService.GetStrand(duplexSheet.AntiSenseStrandId);
                if (antiSenseStrand == null)
                {
                    antiSenseStrandModel.SetError("", "");
                }

                var senseStrandModel = new StrandModel {
                    StrandId = duplexSheet.SenseStrandId
                };
                var senseStrand = _duplexesService.GetStrand(duplexSheet.SenseStrandId);
                if (senseStrand == null)
                {
                    senseStrandModel.SetError("", "");
                }

                Mapper.Map(antiSenseStrand, antiSenseStrandModel);
                Mapper.Map(senseStrand, senseStrandModel);

                var targetModel = new TargetModel();
                Mapper.Map(senseStrandModel.Target, targetModel);

                if (antiSenseStrandModel.Target == null || senseStrandModel.Target == null ||
                    antiSenseStrandModel.Target.Id != senseStrandModel.Target.Id)
                {
                    targetModel.SetError("", "");
                }

                var duplexModel = new ImportedDuplexModel
                {
                    Target          = targetModel,
                    AntiSenseStrand = antiSenseStrandModel,
                    SenseStrand     = senseStrandModel,
                    MW = senseStrandModel.MW + antiSenseStrandModel.MW
                };
                model.Add(duplexModel);
            }

            return(Ok(model));
        }
Ejemplo n.º 4
0
        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));
        }