Esempio n. 1
0
        public IHttpActionResult Update([FromBody] StrandModel model)
        {
            var strandId = model.Id;
            var strand   = _strandsService.GetStrand(strandId);

            if (strand != null)
            {
                Mapper.Map(model, strand, opt => opt.BeforeMap((src, dest) =>
                {
                    dest.Species.Clear();
                    dest.StrandModStructures.Clear();
                }));

                if (!_strandsService.IsStrandExists(strand))
                {
                    _strandsService.UpdateStrand(strand);
                }
                else
                {
                    model.SetError("Name", "Duplicate strand name");
                }
            }

            return(Ok(model));
        }
Esempio n. 2
0
        public IHttpActionResult Get(int strandId)
        {
            var strand = _strandsService.GetStrand(strandId);

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

            var hasAssociations = _strandsService.HasAssociations(strandId);
            var model           = new StrandModel {
                HasAssociations = hasAssociations
            };

            Mapper.Map(strand, model);
            return(Ok(model));
        }
Esempio n. 3
0
        public IHttpActionResult Create([FromBody] StrandModel model)
        {
            try
            {
                var strand = new Strand();
                Mapper.Map(model, strand);
                if (!_strandsService.IsStrandExists(strand))
                {
                    _strandsService.CreateStrand(strand);
                    model.Id = strand.Id;
                }
                else
                {
                    model.SetError("Sequence", "Duplicate strand");
                }

                return(Ok(model));
            }
            catch (Exception)
            {
                return(InternalServerError());
            }
        }
Esempio n. 4
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));
        }