Example #1
0
        public async Task <ServiceResponds <GetWolveDto> > UpdateWolve(UpDateWolveDto updateWolve)
        {
            ServiceResponds <GetWolveDto> serviceResponds = new ServiceResponds <GetWolveDto>();

            try
            {
                Wolve wolve = await _context.Wolves.FirstOrDefaultAsync(c => c.Id == updateWolve.Id);

                wolve.Name     = updateWolve.Name;
                wolve.Gender   = updateWolve.Gender;
                wolve.Birthday = updateWolve.Birthday;
                wolve.Latitide = updateWolve.Latitide;
                wolve.Logitude = updateWolve.Logitude;

                _context.Wolves.Update(wolve);
                await _context.SaveChangesAsync();

                serviceResponds.Data = _mapper.Map <GetWolveDto>(wolve);
            }

            catch (Exception ex)
            {
                serviceResponds.Success = false;
                serviceResponds.Message = ex.Message;
            }

            return(serviceResponds);
        }
Example #2
0
        public async Task <ServiceResponds <GetWolveDto> > GetWolveById(int id)
        {
            ServiceResponds <GetWolveDto> serviceResponds = new ServiceResponds <GetWolveDto>();
            Wolve dbWolve = await _context.Wolves.FirstOrDefaultAsync(c => c.Id == id);

            serviceResponds.Data = _mapper.Map <GetWolveDto>(dbWolve);
            return(serviceResponds);
        }
Example #3
0
        public async Task <ServiceResponds <List <GetWolveDto> > > AddWolve(AddWolveDto newWolve)

        {
            ServiceResponds <List <GetWolveDto> > serviceResponds = new ServiceResponds <List <GetWolveDto> >();
            Wolve wolve = _mapper.Map <Wolve>(newWolve);
            await _context.Wolves.AddAsync(wolve);

            await _context.SaveChangesAsync();

            serviceResponds.Data = _context.Wolves.Select(c => _mapper.Map <GetWolveDto>(c)).ToList();
            return(serviceResponds);
        }
Example #4
0
        public async Task <ServiceResponds <int> > AddWolveToPack(int packId, int wolveId)
        {
            Wolve dbWolve = await _context.Wolves.FirstOrDefaultAsync(c => c.Id == wolveId);

            Pack dbpack = await _context.Packs.FirstOrDefaultAsync(c => c.Id == packId);

            dbWolve.Pack = dbpack;
            _context.Wolves.Add(dbWolve);
            _context.Entry(dbWolve).State = EntityState.Unchanged;
            //  dbWolve.Pack.Id = dbpack.Id;
            _context.Wolves.Update(dbWolve);
            await _context.SaveChangesAsync();

            ServiceResponds <int> responds = new ServiceResponds <int>();

            responds.Data = dbWolve.Id;
            return(responds);
        }
Example #5
0
        public async Task <ServiceResponds <List <GetWolveDto> > > DeleteWolve(int id)
        {
            ServiceResponds <List <GetWolveDto> > serviceResponds = new ServiceResponds <List <GetWolveDto> >();

            try{
                Wolve wolve = await _context.Wolves.FirstAsync(c => c.Id == id);

                _context.Wolves.Remove(wolve);
                await _context.SaveChangesAsync();

                serviceResponds.Data = _context.Wolves.Select(c => _mapper.Map <GetWolveDto>(c)).ToList();;
            }

            catch (Exception ex)

            {
                serviceResponds.Success = false;
                serviceResponds.Message = ex.Message;
            }

            return(serviceResponds);
        }