コード例 #1
0
        public async Task <ISingleResponse <DtoContact> > GetContact(int contactId)
        {
            var response            = new SingleResponse <DtoContact>();
            var getContactByIdQuery = _contactRepository.GetAll().Where(x => x.Id == contactId);

            if (await getContactByIdQuery.AnyAsync())
            {
                response.Model = _mapper.Map <DtoContact>(await getContactByIdQuery.FirstOrDefaultAsync());
                response.SetResponse(false, HttpResponseMessages.DATA_FOUND_SUCCESS, HttpStatusCode.OK);
            }
            else
            {
                response.Model = null;
                response.SetResponse(false, HttpResponseMessages.NO_DATA_FOUND, HttpStatusCode.OK);
            }
            return(response);
        }
コード例 #2
0
ファイル: UserService.cs プロジェクト: lucaslatorre/APIConf
        public async Task <ISingleResponse <DtoUser> > RemoveUser(int UserId)
        {
            var response    = new SingleResponse <DtoUser>();
            var UserDbModel = await _UserRepository.GetAll().Where(x => x.Id == UserId).FirstOrDefaultAsync();

            if (UserDbModel != null)
            {
                await _UserRepository.DeleteAsync(UserDbModel);

                response.Model = _mapper.Map <DtoUser>(UserDbModel);
                response.SetResponse(false, HttpResponseMessages.DATA_DELETE_SUCCESS, HttpStatusCode.OK);
            }
            else
            {
                response.Model = null;
                response.SetResponse(true, HttpResponseMessages.NO_DATA_FOUND, HttpStatusCode.OK);
            }
            return(response);
        }
コード例 #3
0
ファイル: UserService.cs プロジェクト: lucaslatorre/APIConf
        public async Task <ISingleResponse <DtoUser> > AddUser(AddUser UserToAdd)
        {
            var response    = new SingleResponse <DtoUser>();
            var UserDbModel = _mapper.Map <User>(UserToAdd);

            await _UserRepository.AddAsync(UserDbModel);

            response.Model = _mapper.Map <DtoUser>(UserDbModel);
            response.SetResponse(false, HttpResponseMessages.DATA_ADD_SUCCESS, HttpStatusCode.OK);
            return(response);
        }
コード例 #4
0
        public async Task <ISingleResponse <DtoContact> > InactiveContact(int contactId)
        {
            var response       = new SingleResponse <DtoContact>();
            var contactDbModel = await _contactRepository.GetAll().Where(x => x.Id == contactId).FirstOrDefaultAsync();

            if (contactDbModel != null)
            {
                contactDbModel.Status = false;
                await _contactRepository.UpdateAsync(contactDbModel);

                response.Model = _mapper.Map <DtoContact>(contactDbModel);
                response.SetResponse(false, HttpResponseMessages.DATA_UPDATE_SUCCESS, HttpStatusCode.OK);
            }
            else
            {
                response.Model = null;
                response.SetResponse(true, HttpResponseMessages.NO_DATA_FOUND, HttpStatusCode.OK);
            }
            return(response);
        }
コード例 #5
0
        public async Task <ISingleResponse <DtoContact> > AddContact(AddContact contactToAdd)
        {
            var response       = new SingleResponse <DtoContact>();
            var contactDbModel = _mapper.Map <UserContact>(contactToAdd);

            contactDbModel.Status = true;
            await _contactRepository.AddAsync(contactDbModel);

            response.Model = _mapper.Map <DtoContact>(contactDbModel);
            response.SetResponse(false, HttpResponseMessages.DATA_ADD_SUCCESS, HttpStatusCode.OK);
            return(response);
        }