Beispiel #1
0
        private Area Mapear(AreaInputModel areaInputModel)
        {
            var area = new Area
            {
                CodigoArea = areaInputModel.CodigoArea,
                NombreArea = areaInputModel.NombreArea
            };

            return(area);
        }
Beispiel #2
0
        private Area MapearArea(AreaInputModel areaInput)
        {
            var area = new Area
            {
                IdArea = areaInput.IdArea,
                Nombre = areaInput.Nombre
            };

            return(area);
        }
Beispiel #3
0
        public ActionResult <AreaViewModel> Post(AreaInputModel areaInputModel)
        {
            Area area     = Mapear(areaInputModel);
            var  response = _AreaService.Guardar(area);

            if (response.Error)
            {
                ModelState.AddModelError("Guardar area", response.Mensaje);
                var problemDetails = new ValidationProblemDetails(ModelState)
                {
                    Status = StatusCodes.Status400BadRequest,
                };
                return(BadRequest(problemDetails));
            }
            return(Ok(response.Area));
        }
        public async Task <IActionResult> Post(AreaInputModel areaInput)
        {
            var existsByName = this.areasService.Exists(x => x.Name == areaInput.Name);

            var response = new Response()
            {
                Message = "Successfully added area!",
            };

            if (!this.ModelState.IsValid || existsByName)
            {
                response.Message = "Area with that name already exists..";
                return(this.BadRequest(response));
            }

            await this.areasService.AddAsync(areaInput);

            return(this.Ok(response));
        }
Beispiel #5
0
        public async Task <ActionResult <AreaViewModel> > PostAsync(AreaInputModel areaInput)
        {
            Area area     = MapearArea(areaInput);
            var  response = _areaService.Guardar(area);

            if (response.Error)
            {
                ModelState.AddModelError("Guardar Area", response.Mensaje);
                var problemDetails = new ValidationProblemDetails(ModelState)
                {
                    Status = StatusCodes.Status400BadRequest,
                };
                return(BadRequest(problemDetails));
            }
            var areaViewModel = new AreaViewModel(response.Area);
            await _hubContext.Clients.All.SendAsync("AreaRegistrada", areaViewModel);

            return(Ok(areaViewModel));
        }