Beispiel #1
0
        public IActionResult CreateClassEntity(
            [FromBody]  ClassEntityForCreationDto newClassEntityDto)
        {
            if (newClassEntityDto == null)
            {
                return(BadRequest());
            }

            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }


            if (_repo.ClassEntityExists(newClassEntityDto.OwnerIdentityName))
            {
                return(BadRequest("You already have a class."));
            }



            var finalClassEntity = _mapper.Map <Entities.ClassEntity>(newClassEntityDto);

            _repo.AddClassEntity(finalClassEntity);
            if (!_repo.Save())
            {
                return(StatusCode(500, $"A problem happened while handling your request to create a class for user {newClassEntityDto.OwnerIdentityName}."));
            }
            var createdClassEntityToReturn = _mapper.Map <ClassEntityDto>(finalClassEntity);

            return(CreatedAtAction("GetClassEntityByOwnerIdentityName", new
                                   { ownerIdentityName = createdClassEntityToReturn.OwnerIdentityName }, createdClassEntityToReturn));
        }
        public async Task <ClassEntityDto> AddClassEntity(ClassEntityForCreationDto classEntityForCreation)
        {
            var classEntityForCreationJson =
                new StringContent(JsonSerializer.Serialize(classEntityForCreation), Encoding.UTF8, "application/json");

            var response = await _httpClient.PostAsync("api/classentities", classEntityForCreationJson);

            if (response.IsSuccessStatusCode)
            {
                return(await JsonSerializer.DeserializeAsync <ClassEntityDto>(await response.Content.ReadAsStreamAsync()));
            }

            return(null);
        }
        public IActionResult CreateClassEntity(
            [FromBody]  ClassEntityForCreationDto newClassEntityDto)
        {
            if (newClassEntityDto == null)
            {
                return(BadRequest());
            }

            //if (newClassEntityDto.Name == "testforbadname")
            //{
            //    ModelState.AddModelError("Description", "The provided description should be different from the name.");
            //}

            if (ModelState.IsValid == false)
            {
                return(BadRequest(ModelState));
            }


            if (_repo.ClassEntityExists(newClassEntityDto.OwnerIdentityName))
            {
                return(BadRequest("You already have a class."));
            }



            var finalClassEntity = _mapper.Map <Entities.ClassEntity>(newClassEntityDto);

            _repo.AddClassEntity(finalClassEntity);
            if (!_repo.Save())
            {
                return(StatusCode(500, $"A problem happened while handling your request to create a class for user {newClassEntityDto.OwnerIdentityName}."));
            }
            var createdClassEntityToReturn = _mapper.Map <ClassEntityDto>(finalClassEntity);

            return(CreatedAtAction("GetClassEntityByOwnerIdentityName", new
                                   { ownerIdentityName = createdClassEntityToReturn.OwnerIdentityName }, createdClassEntityToReturn));
        }
 private void ResetDialog(string loggedInUserName)
 {
     ClassEntity = new ClassEntityForCreationDto {
         OwnerIdentityName = loggedInUserName
     };                                                                                   // _sessionDataService.LoggedInUserName };
 }