コード例 #1
0
        public async Task <IActionResult> UpdateFloorPlan(int id, UpdateFloorPlanModel model)
        {
            var entity = _service.Floors.Id(id).FirstOrDefault();

            if (entity == null)
            {
                return(NotFound(new AppResultBuilder().NotFound()));
            }
            var validationResult = _service.ValidateUpdateFloorPlan(User, entity, model);

            if (!validationResult.Valid)
            {
                return(BadRequest(validationResult.Result));
            }
            var metadata = GetFileDestinationMetadata();
            var file     = await _fileService.GetFileAsync(model.File, metadata);

            var ext = file.Extension;

            if (!ext.Equals(".svg"))
            {
                return(BadRequest(ValidationResult.Fail(
                                      new AppResultBuilder().FailValidation(mess: "Invalid file extension"))));
            }
            await _service.UpdateFloorPlanSvgAsync(entity, model, file);

            context.SaveChanges();
            return(NoContent());
        }