public async Task <IActionResult> Create([FromBody] NeuerKontokorrentRequest request)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     try
     {
         await _kontokorrentsService.Erstellen(new Models.NeuerKontokorrent()
         {
             Id   = request.Id,
             Name = request.Name,
             OeffentlicherName = request.OeffentlicherName,
             Personen          = request.Personen.Select(v => new Models.NeuePerson()
             {
                 Name = v.Name, Id = v.Id
             }).ToArray(),
             Privat = string.IsNullOrEmpty(request.OeffentlicherName)
         }, User.GetId());
     }
     catch (NameExistsException)
     {
         return(UnprocessableEntity("Kontokorrent existiert bereits"));
     }
     return(Ok());
 }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([FromBody] NeuerKontokorrentRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            try
            {
                var newId = Guid.NewGuid().ToString();
                await kontokorrentsService.Erstellen(new Models.NeuerKontokorrent()
                {
                    Id   = newId,
                    Name = request.Secret,
                    OeffentlicherName = request.Secret.ToLower(),
                    Personen          = request.Personen.Select(p => new Models.NeuePerson()
                    {
                        Name = p.Name
                    }).ToArray(),
                    Privat = false
                }, null);

                var personenStatus = await kontokorrentsService.GetPersonenStatus(newId);

                var response = new NeuerKontokorrentResponse()
                {
                    PersonenStatus = personenStatus.Select(p => new ApiModels.v1.PersonenStatus()
                    {
                        Person = new ApiModels.v1.Person()
                        {
                            Id   = p.Person.Id,
                            Name = p.Person.Name
                        },
                        Wert = p.Wert
                    }).ToArray(),
                    Token = (await tokenService.CreateTokenAsync(newId)).Token
                };
                return(Ok(response));
            }
            catch (NameExistsException)
            {
                return(BadRequest("Secret existiert bereits"));
            }
        }