Exemplo n.º 1
0
        public async Task <ActionResult <DataAccess.Number> > Delete(int id)
        {
            try
            {
                //does the number exist?
                BusinessLogic.Number num = await _repository.GetNumberAsync(id);

                //if the answer is "Nope!"
                if (num == null)
                {
                    return(NotFound());
                }

                //otherwise give it the boot
                await _repository.RemoveNumberAtIndexAsync(num);

                //report a sucessful booting
                return(NoContent());
            }
            catch (Exception e)
            {
                string danger = "While the server isn't on fire... for now... your number wasn't found: " + e.Message;
                return(StatusCode(StatusCodes.Status500InternalServerError, danger));
            }
        }
Exemplo n.º 2
0
        public async Task UpdateNumberAsync(BusinessLogic.Number num)
        {
            Number updated = await _dbContext.Number.FirstOrDefaultAsync(x => num.Id == x.Id);

            updated.IntNum = num.IntNumber;

            await _dbContext.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public DataAccess.Number MapNumber(BusinessLogic.Number number)
        {
            //just place the value into a Number entity
            DataAccess.Number num = new DataAccess.Number();

            //return the entity
            return(num);
        }
Exemplo n.º 4
0
        public BusinessLogic.Number MapNumber(DataAccess.Number number)
        {
            //get the value and id from the database
            BusinessLogic.Number num = new BusinessLogic.Number(number.IntNum);
            num.Id = number.Id;

            //return it
            return(num);
        }
Exemplo n.º 5
0
        public async Task PlaceNumberAsync(BusinessLogic.Number num)
        {
            DataAccess.Number numb = new DataAccess.Number()
            {
                IntNum = num.IntNumber
            };
            await _dbContext.AddAsync(numb);

            await _dbContext.SaveChangesAsync();
        }
Exemplo n.º 6
0
        public async Task RemoveNumberAtIndexAsync(BusinessLogic.Number num)
        {
            //get the entity to be removed
            Number deleted = await _dbContext.Number.FirstOrDefaultAsync(x => num.Id == x.Id);

            //flag it for deletion
            _dbContext.Number.Remove(deleted);

            //do the deletion
            await _dbContext.SaveChangesAsync();
        }
Exemplo n.º 7
0
        public async Task <ActionResult <BusinessLogic.Number> > GetNum(int id)
        {
            try
            {
                BusinessLogic.Number num = await _repository.GetNumberAsync(id);

                return(num);
            }
            catch (Exception e)
            {
                string danger = $"Warning: Gremlins in server, number at {id} missing:" + e.Message;
                return(StatusCode(StatusCodes.Status500InternalServerError, danger));
            }
        }
Exemplo n.º 8
0
        public async Task <ActionResult <BusinessLogic.Number> > Get()
        {
            try
            {
                //just return the first number
                BusinessLogic.Number num = await _repository.GetNumberAsync(1);


                return(Ok(num));
            }
            catch (Exception e)
            {
                string danger = "Danger Will Robinson: Server Meltdown Eminant: " + e.Message;
                return(StatusCode(StatusCodes.Status500InternalServerError, danger));
            }
        }
Exemplo n.º 9
0
        public async Task <ActionResult <object> > Put(int id, int num)
        {
            try
            {
                BusinessLogic.Number number = new BusinessLogic.Number(num);
                number.Id = id;
                await _repository.UpdateNumberAsync(number);

                return(Ok());
            }
            catch (Exception e)
            {
                string danger = "The number is on vacation in Palm Springs and is Not Found: " + e.Message;
                return(NotFound(danger));
            }
        }
Exemplo n.º 10
0
        public async Task <ActionResult <object> > PosttoSB(int num)
        {
            try
            {
                //declare the Number
                BusinessLogic.Number numbr = new BusinessLogic.Number(num);

                //put it in the db.
                await _repository.PlaceNumberAsync(numbr);

                //then put a message into the service bus
                await _serviceBusSender.SendMessage(numbr);

                return(Ok());
            }

            catch (Exception e)
            {
                string danger = "The database was unable to post to DB for... reasons. : " + e.Message;
                return(StatusCode(StatusCodes.Status500InternalServerError, danger));
            }
        }