Beispiel #1
0
 public ValidationResult ValidateUpdateFloorPlan(
     ClaimsPrincipal principal,
     Floor entity,
     UpdateFloorPlanModel model)
 {
     return(ValidationResult.Pass());
 }
        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());
        }
Beispiel #3
0
        public async Task UpdateFloorPlanSvgAsync(Floor entity, UpdateFloorPlanModel model,
                                                  IFile file)
        {
            using (var stream = await file.OpenReadAsync())
                using (var reader = new StreamReader(stream))
                {
                    var svg = await reader.ReadToEndAsync();

                    UpdateFloorPlanSvg(entity, svg);
                }
        }