Exemple #1
0
        public IActionResult Update(int id, FormFactor dto)
        {
            var formFactor = _context.FormFactors
                             .FirstOrDefault(formFactor => formFactor.Id == id);

            if (formFactor == null)
            {
                return(new NotFoundObjectResult($"FormFactor with id {id} not found"));
            }

            if (dto.Name == null)
            {
                return(new BadRequestObjectResult("Name must not be null"));
            }

            if (dto.Name.Length < 1)
            {
                return(new BadRequestObjectResult("Name must be atleast 1 character"));
            }

            if (dto.Name.Length > 256)
            {
                return(new BadRequestObjectResult("Name must not be more than 256 characters"));
            }

            formFactor.Name = dto.Name;

            _context.SaveChanges();

            return(new OkObjectResult(formFactor));
        }
Exemple #2
0
        private static void SeedFormFactors(AssetTrackerContext context)
        {
            if (context.FormFactors.Any())
            {
                return;
            }

            var formFactors = new FormFactor[]
            {
                new FormFactor {
                    Name = "Desktop",
                },
                new FormFactor {
                    Name = "Laptop",
                },
                new FormFactor {
                    Name = "Phone",
                },
                new FormFactor {
                    Name = "Tablet",
                }
            };

            foreach (var formFactor in formFactors)
            {
                context.FormFactors.Add(formFactor);
            }

            context.SaveChanges();
        }
Exemple #3
0
        public IActionResult Create(FormFactor dto)
        {
            if (dto.Name == null)
            {
                return(new BadRequestObjectResult("Name must not be null"));
            }

            if (dto.Name.Length < 1)
            {
                return(new BadRequestObjectResult("Name must be atleast 1 character"));
            }

            if (dto.Name.Length > 256)
            {
                return(new BadRequestObjectResult("Name must not be more than 256 characters"));
            }

            _context.FormFactors.Add(dto);
            _context.SaveChanges();

            return(new OkObjectResult(dto));
        }