Ejemplo n.º 1
0
        public async Task <(WolfModel, ValidationResult)> Create(WolfForModificationModel wolfForModification)
        {
            // We need to validate that the model is valid
            var validator       = new WolfForModificationValidator();
            var validatorResult = await validator.ValidateAsync(wolfForModification);

            if (!validatorResult.IsValid)
            {
                return(null, validatorResult);
            }

            // All is ok we can add the object
            var wolf = new Wolf
            {
                FirstName     = wolfForModification.FirstName,
                InsertionName = wolfForModification.InsertionName,
                LastName      = wolfForModification.LastName,
                Gender        = wolfForModification.Gender,
                BirthDate     = wolfForModification.BirthDate,
                Latitude      = wolfForModification.Latitude,
                Longitude     = wolfForModification.Longitude,
                CreatedOnDateTimeOffsetUtc    = DateTimeOffset.UtcNow,
                LastModifiedDateTimeOffsetUtc = DateTimeOffset.UtcNow
            };

            _dbContext.Add(wolf);
            await _dbContext.SaveChangesAsync();

            return(wolf.ToWolfModel(), null);
        }
Ejemplo n.º 2
0
        public async Task <Enums.ServiceResult> AddWolfToPack(WolfPackForModificationModel wolfPackForModification)
        {
            // Try to get the wolf and pack
            var wolf = await _dbContext.Wolfs.FirstOrDefaultAsync(w => w.Id == wolfPackForModification.WolfId);

            var pack = await _dbContext.Packs.FirstOrDefaultAsync(w => w.Id == wolfPackForModification.PackId);

            if (wolf == null || pack == null)
            {
                return(Enums.ServiceResult.NotFound);
            }

            // Check if relationship already exists
            // If it does its ok to just say it was created
            var existingWolfPack = await _dbContext.WolfPack.FirstOrDefaultAsync(w => w.WolfId == wolfPackForModification.WolfId && w.PackId == wolfPackForModification.PackId);

            if (existingWolfPack != null)
            {
                return(Enums.ServiceResult.Ok);
            }

            var wolfPack = new WolfPack
            {
                WolfId = wolfPackForModification.WolfId,
                PackId = wolfPackForModification.PackId
            };

            _dbContext.Add(wolfPack);
            await _dbContext.SaveChangesAsync();

            return(Enums.ServiceResult.Ok);
        }
Ejemplo n.º 3
0
        public async Task <(PackModel, ValidationResult)> Create(PackForModificationModel packForModificationModel)
        {
            // We need to validate that the model is valid
            var validator       = new PackForModificationValidator();
            var validatorResult = await validator.ValidateAsync(packForModificationModel);

            if (!validatorResult.IsValid)
            {
                return(null, validatorResult);
            }

            // All is ok we can add the object
            var pack = new Pack
            {
                Name        = packForModificationModel.Name,
                Description = packForModificationModel.Description,
                CreatedOnDateTimeOffsetUtc    = DateTimeOffset.UtcNow,
                LastModifiedDateTimeOffsetUtc = DateTimeOffset.UtcNow
            };

            _dbContext.Add(pack);
            await _dbContext.SaveChangesAsync();

            return(pack.ToPackModel(), null);
        }
        public void Post([FromBody] string value)
        {
            User user = new User();

            user.Name = value;
            user.Age  = 26;

            _db.Add(user);
            _db.SaveChanges();
        }
Ejemplo n.º 5
0
        public void CreateCamera(Camera camera)
        {
            var existing = _ctx.Cameras.FirstOrDefault(c => c.IpAddress == camera.IpAddress);

            if (existing != null)
            {
                throw new ArgumentException($"Camera with IP: {existing.IpAddress} already exists");
            }

            camera.Id     = 0;
            camera.Status = CameraStatus.Offline;

            _ctx.Add(camera);
            _ctx.SaveChanges();
        }