예제 #1
0
        public async Task <ActionResult <Data.Models.NummerInformation> > HoleNummerInformation(HoleNummerInformationRequest holeNummerInformationRequest)
        {
            Data.Models.NummerInformation nummerInformation = null;

            NummerDefinition foundNummerDefinition = this._context.Nummerdefinitionen.Include("NummerDefinitionQuellen").Where(e => (e.Id == holeNummerInformationRequest.Nummer_definition_id)).FirstOrDefault();

            if (foundNummerDefinition == null)
            {
                throw new Exception(string.Format("für die nummer_definition_id = '{0}' existiert keine gültig Nummerdefinition.", holeNummerInformationRequest.Nummer_definition_id));
            }
            else if (holeNummerInformationRequest.DurchQuellen && (foundNummerDefinition.NummerDefinitionQuellen == null || foundNummerDefinition.NummerDefinitionQuellen.Count == 0))
            {
                throw new Exception("Für die Nummerdefinition sind keine Quellen definiert.");
            }
            else if (holeNummerInformationRequest.DurchQuellen && (foundNummerDefinition.NummerDefinitionQuellen.Count != holeNummerInformationRequest.Quellen.Count()))
            {
                throw new Exception("Die Anzahl der definierten Quellen stimmt nicht mit der Anzahl der übergebenen Quellen überein.");
            }
            else if (!holeNummerInformationRequest.DurchQuellen && holeNummerInformationRequest.Ziel == null)
            {
                throw new ArgumentNullException(nameof(holeNummerInformationRequest.Ziel));
            }
            else
            {
                if (holeNummerInformationRequest.DurchQuellen)
                {
                    string rawSQL = NummerInformationRawSQLGenerator.GenersateRawSQL(holeNummerInformationRequest.Nummer_definition_id, foundNummerDefinition.NummerDefinitionQuellen, holeNummerInformationRequest.Quellen);
                    List <NummerInformation> nummerInformations = await this._context.Nummerinformationen.FromSqlRaw(rawSQL).ToListAsync();

                    if (nummerInformations != null && nummerInformations.Count > 0)
                    {
                        nummerInformation = nummerInformations.FirstOrDefault();
                    }
                    else
                    {
                        return(this.NotFound());
                    }
                }
                else
                {
                    string ziel = holeNummerInformationRequest.Ziel.ToString();
                    nummerInformation = await this._context.Nummerinformationen.Where(e => e.NummerdefinitionenId == foundNummerDefinition.Id && e.Ziel == ziel).FirstOrDefaultAsync();
                }
                if (nummerInformation != null)
                {
                    return(nummerInformation);
                }
                else
                {
                    return(this.NotFound());
                }
            }
        }
예제 #2
0
        public async Task <ActionResult <Data.Models.NummerInformation> > SetzeZielFürNummerInformation(SetzeZielFürNummerInformationRequest setzeZielFürNummerInformationRequest)
        {
            Data.Models.NummerInformation nummerInformation = null;

            if (setzeZielFürNummerInformationRequest == null)
            {
                throw new ArgumentNullException(nameof(setzeZielFürNummerInformationRequest));
            }

            if (setzeZielFürNummerInformationRequest.NummerInformationGuid == null)
            {
                throw new ArgumentNullException(nameof(setzeZielFürNummerInformationRequest.NummerInformationGuid));
            }

            if (setzeZielFürNummerInformationRequest.Ziel == null)
            {
                throw new ArgumentNullException(nameof(setzeZielFürNummerInformationRequest.Ziel));
            }
            //TODO BK Ziel muss für jede Definition eindeutig sein.
            else
            {
                Guid guid = (Guid)setzeZielFürNummerInformationRequest.NummerInformationGuid;
                nummerInformation = await this._context.Nummerinformationen.Where(e => (e.Guid != null && e.Guid.ToString() == guid.ToString())).FirstOrDefaultAsync();

                if (nummerInformation == null)
                {
                    return(NotFound());
                }
                else
                {
                    string ziel = setzeZielFürNummerInformationRequest.Ziel.ToString();
                    nummerInformation.Ziel = ziel;
                    _context.Entry(nummerInformation).State = EntityState.Modified;
                    try
                    {
                        await this._context.SaveChangesAsync();

                        return(Ok(nummerInformation));
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        return(StatusCode((int)HttpStatusCode.InternalServerError));
                    }
                }
            }
        }
예제 #3
0
        public async Task <ActionResult <Guid?> > ErstelleNummerInformation(ErstelleNummerInformationRequest erstelleNummerInformationRequest)
        {
            Guid?guid = null;

            NummerDefinition foundNummerDefinition = this._context.Nummerdefinitionen.Include("NummerDefinitionQuellen").Where(e => (e.Id == erstelleNummerInformationRequest.Nummer_definition_id)).FirstOrDefault();

            if (foundNummerDefinition == null)
            {
                throw new Exception(string.Format("für die nummer_definition_id = '{0}' existiert keine gültig Nummerdefinition.", erstelleNummerInformationRequest.Nummer_definition_id));
            }
            else if (foundNummerDefinition.NummerDefinitionQuellen == null || foundNummerDefinition.NummerDefinitionQuellen.Count == 0)
            {
                throw new Exception("Für die Nummerdefinition sind keine Quellen definiert.");
            }
            else if (foundNummerDefinition.NummerDefinitionQuellen.Count != erstelleNummerInformationRequest.Quellen.Count())
            {
                throw new Exception("Die Anzahl der definierten Quellen stimmt nicht mit der Anzahl der übergebenen Quellen überein.");
            }
            //else if (erstelleNummerInformation.Ziel == null)
            //{
            //    throw new Exception("Das Ziel ist null.");
            //}
            else
            {
                Data.Models.NummerInformation nummerInformation = new Data.Models.NummerInformation();
                nummerInformation.NummerdefinitionenId = erstelleNummerInformationRequest.Nummer_definition_id;
                string jsonQuellen = NumberInformationJSONGenerator.GenerateJSON(foundNummerDefinition.NummerDefinitionQuellen, erstelleNummerInformationRequest.Quellen);
                nummerInformation.Quelle = jsonQuellen;
                nummerInformation.Ziel   = erstelleNummerInformationRequest.Ziel != null?erstelleNummerInformationRequest.Ziel.ToString() : null;

                this._context.Nummerinformationen.Add(nummerInformation);
                await this._context.SaveChangesAsync();

                guid = nummerInformation.Guid;
            }

            return(guid);
        }